if $request_uri [not static file], then ...

Joe Aston joe at joeaston.com
Sat Nov 8 15:02:52 MSK 2008


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 <cynix at cynix.org> wrote:
> Joe Aston <joe at ...> 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?
>>
>> Thanks!
>>
>>
>
> 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;
> }
>
>
>





More information about the nginx mailing list