Match any location except particular one

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

engine/
__index.php
webroot/
__images/
__css/
__cms/
______engine/
_________index.php
______webroot/
_________images/
_________css/
others/

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;
server_name glinka.fm;
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:
http://forum.nginx.org/read.php?2,218819,218819#msg-218819

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 D. [email protected]

Thanks but i’ve already found a solution in the russian nginx forum.

location ~ ^/cms/(.*)$ {
try_files /webroot/cms/webroot/$1 /webroot/cms/engine/index.php;
}

Is what i needed.

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

On Wed, Nov 23, 2011 at 10:11:08AM -0500, mennanov wrote:

Thanks but i’ve already found a solution in the russian nginx forum.

location ~ ^/cms/(.*)$ {
try_files /webroot/cms/webroot/$1 /webroot/cms/engine/index.php;
}

Is what i needed.

location /cms/ {
alias /home/renat/www/glinka/webroot/cms/webroot/;
try_files $uri /webroot/cms/engine/index.php;
}


Igor S.

Igor S. Wrote:

Is what i needed.
Igor S.


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Is there any way to use relative path in alias?
It does not look comfortable to write the whole absolute path, it would
be rather better if it is current root + path

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

On Wed, Nov 23, 2011 at 11:26:02AM -0500, mennanov wrote:

}

be rather better if it is current root + path
alias is more flexible root.


Igor S.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs