7 messages in ru.sysoev.nginxRe: if $request_uri [not static file]...
FromSent OnAttachments
Joe AstonNov 7, 2008 5:21 pm 
cynixNov 7, 2008 10:38 pm 
Joe AstonNov 8, 2008 4:02 am 
RoxisNov 8, 2008 4:38 am 
Joe AstonNov 8, 2008 5:30 am 
Fernando PerezNov 11, 2008 2:35 am 
Joe AstonNov 11, 2008 3:59 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: if $request_uri [not static file], then ...Actions...
From:Joe Aston (jo@joeaston.com)
Date:Nov 8, 2008 4:02:29 am
List:ru.sysoev.nginx

Sorry, I did not make myself clear. I already have a fastcgi handler section.

I think the problem is with the regular expression in " if ($request_uri !~* (js|css|images|etc)$) ":

location / { root /var/www/domain.com/public; index index.php;

# DO NOT WANT TO USE THIS METHOD (WHICH WORKS): # # If the file exists as a static file serve it # directly without running all # the other rewite tests on it # # if (-f $request_filename) { # break; # } # if (!-f $request_filename) { # rewrite ^/(.+)$ /index.php?q=$1 last; # break; # }

# WANT TO USE THIS METHOD INSTEAD (WHICH ISN'T WORKING): # # If request doesn't match js / css / images / etc # send request to fastcgi handler # if ($request_uri !~* (js|css|images|etc)$) { rewrite ^/(.+)$ /index.php?q=$1 last; break; } }

location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/domain.com/public$fastcgi_script_name;

fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; }

On Sat, Nov 8, 2008 at 6:38 AM, cynix <cyn@cynix.org> wrote:

Joe Aston <joe@...> writes:

How can I achieve the following?

I want to redirect all non-file requests to a script, like this:

if ($request_uri !~* (js|css|images|etc)$) { rewrite ^/(.+)$ /index.php?q=$1 last; break; }

...but this does not work. I do not want to use "if (!-f $request_filename)" to avoid disk overhead.

Can anyone make a suggestion?

location / { error_page 404 = @handler; log_not_found off; }

location @handler { fastcgi_pass 127.0.0.1:1234; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_param QUERY_STRING q=$request_uri&$query_string; }