Match any location except particular one

Francis Daly francis at daoine.org
Wed Nov 23 14:45:56 UTC 2011


On Wed, Nov 23, 2011 at 08:27:55AM -0500, mennanov wrote:

Hi there,

> 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:

You have three top-level location{} blocks here.

You probably only want two.

>     location / {

This will match all requests that don't match another location.

>     # rules for /cms/ queries only
>     location /cms/ {

This will match all requests that begin "/cms/", unless they match
another location.

>     location ~ \.php$ {

This will match all requests that end in ".php". Specifically including
both "/index.php" and "/cms/index.php". Which is likely not what you want.

In nginx, every request is handled by one location{} block.

See, for example, http://wiki.nginx.org/HttpCoreModule#location for
details of how the one is chosen.

So you probably want something like

  location / {
   # all "location /" config
   location ~ \.php$ {
    # all "php inside location /" config
   }
  }

  location /cms/ {
   # all "location /cms/" config
   location ~ \.php$ {
    # all "php inside location /cms/" config
   }
  }

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list