Different FastCGI backend for /subdir: regex not matching

hugo nginx-forum at nginx.us
Thu Aug 11 08:22:52 UTC 2011


I have a virtual host, and for a certain subdirectory I want to use
another fastcgi backend.

What I have now goes something like:
(...)
       location ~ /subdir/ {
               alias /var/www/otheraccount/public_html/;

                # PHP FastCGI
                location ^~ /subdir\/(.+)\.php {
                        return 504;
                        include /usr/pkg/etc/nginx/fastcgi_params;

                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME
/var/www/othervhost/public_html$fastcgi_script_name;

                        try_files $uri =502;
                }
       }

        # PHP FastCGI
        location ~ \.php {
                include /usr/pkg/etc/nginx/fastcgi_params;

                fastcgi_pass 127.0.0.1:9001;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME
/var/www/blah/public_html$fastcgi_script_name;

                try_files $uri =403;
        }
}

Ignore the try_files and bogus return, they're in place to try to trace
what's happening where.

This is nginx 1.0.4, if it matters.

Basically, the problem is that the last try_files is triggered (I get a
403 requesting /subdir/index.php, and if I change that last try_files to
404 then I get a 404); Therefore I conclude the regex trying to catch
php files under /subdir is not effective.

What would the proper regex be ? 
I want it to catch /subdir/*.php, /subdir/subsub/*.php,
/subdir/s/u/b.php, etc

On a related note, trying to access www.vhost.local/subdir (no trailing
/) results in nginx trying to serve subdir from the original root (ie
the alias isn't picked up); It may be a trivial question but I've run
into this in the past. What is the correct way to catch both /subdir and
/subdir/ requests?


I would very much appreciate a reply on this subject, as I've been
struggling with this for hours. Regexes are not my strong point.

Thanks.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,213682,213682#msg-213682



More information about the nginx mailing list