"if" statement breaks try_files?

I’m seeing something really weird. If I put an “if” statement
anywhere within the same block as a “try_files” then it stops working.
It always returns that the file exists even when it doesn’t.

I’m testing against nginx-1.0.9 on a Linux host.

This can be tested with this simple.conf:

worker_processes 1;
events { worker_connections 1024; }
http {
server {
listen 80;
server_name localhost;
root /var/www;
index index.html index.htm index.php;

  location ~ \.php($|/) {
     try_files doesnotexist =405;
     fastcgi_index index.php;
     fastcgi_pass unix:/tmp/php.socket;

     if ($uri) {}

     fastcgi_param  SCRIPT_FILENAME    /var/www$fastcgi_script_name;
     fastcgi_param  HTTPS              off;
     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  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;
     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;
     fastcgi_param  REDIRECT_STATUS    200;


If that “if ($uri)” statement is left in it never returns the 405
error when accessing whatever.php. If you comment out that “if” then
it works as expected and always returns the 405 error.

Any idea what is going on here?


See: If is Evil… when used in location context | NGINX

On Fri, Nov 4, 2011 at 2:13 AM, Nginx U. [email protected] wrote:

See: If is Evil… when used in location context | NGINX

Thanks, I should have known. I had read that but forgotten the most
important parts.

Shame so many projects design their own language when so many proven
works are out there, but I digress.