Match any location except particular one

mennanov nginx-forum at
Wed Nov 23 13:27:55 UTC 2011

Hello, i have a website with the following files structure:


So the folder "cms" is placed in a webroot of the main site. The point
is that all queries like "/js/jquery.js" must be treated as
"/webroot/js/jquery.js" and all cms queries like "/cms/js/jquery.js"
must be treated as "/webroot/cms/webroot/js/jquery.js". I spent 2 days
writing a proper config, the main problem is that all queries to /cms/
location MUST NOT be parsed in "location / {...}" and all queries in
"location /cms/ {...}" must not be parsed in "location / {...}"

Here is my config:

server {
    listen       8080;
    root /home/renat/www/glinka;
    index index.php index.html;

    # rules for all queries except /cms/ (how to do that??) "location ~
/(?!cms)" makes a cycle and 500 error
    location / {
	try_files	/webroot/$uri /engine/index.php;

    # rules for /cms/ queries only
    location /cms/ {
	rewrite /cms/(.*) /webroot/cms/webroot/$1;
	if (!-f $request_filename) {
	    rewrite (.*) /webroot/cms/engine/index.php;

    location ~ \.php$ {
      include fastcgi.conf;

Please help me

Posted at Nginx Forum:,218819,218819#msg-218819

More information about the nginx mailing list