Issue with multiple location blocks to handle two webapps
Nikhil Bhardwaj
goltus at gmail.com
Tue Aug 28 04:39:55 UTC 2012
Hi All,
My webapp is a combination of two apps running on one server.
the community app (smaller one) is located under community directory and
the all urls starting with community should be handled by it
e.g. example.com/community/questionsexample,com/community/2/an-actual-qestion
etc etc
The main app takes care of rest of URLs such as example.com (which should
redirect to example.com/city) example.com/city/sampledir etc etc
the location blocks I have used are
----------------------
#handle community section separately
location ^~ /*community*/ {
try_files $uri $uri/ /index.php?qa-rewrite=$uri&$args;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
access_log off;
}
}
location =/ {
#convert domain to domain/city
rewrite ^(.*)$ $scheme://example.com/city permanent;
}
#these locations always use /city as prefix
location ~^/(biz|biz/|profiles|profiles/) {
rewrite ^(.*)$ $scheme://example.com/city$1 permanent;
}
#main app should handle everything except community
location* /* {
#remove trailing slash
rewrite ^/(.*)/$ /$1 permanent;
#NB this will remove the index.php from the url
try_files $uri $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
access_log off;
}
-------------------------------
With this code the main app works fine but the community app ONLY works for
example.com/community/ and example.com/community/?a=foo/bar etc etc but *NOT
* for example.com/community/foo/bar
I think example.com/community/foo/bar doesn't get handled by the community
location block and goes to the main location which gives 404 error.
I tried various combination for location but nothing is fixing it
perfectly. I will appreciate any pointers / help.
Thanks,
Nikhil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20120827/d489d93b/attachment.html>
More information about the nginx
mailing list