Issue with multiple location blocks to handle two webapps

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

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

On Mon, Aug 27, 2012 at 09:39:55PM -0700, Nikhil Bhardwaj wrote:

Hi there,

location ^~ /*community*/ {
    try_files $uri $uri/ /index.php?qa-rewrite=$uri&$args;

If you ask for /community/foo/bar, this will end up using
/index.php?qa-rewrite=/community/foo/bar&, which will be handled in the
top level “location ~ .php” block.

Perhaps you want

try_files $uri $uri/ /community/index.php?qa-rewrite=$uri&$args;

here? (Not tested by me.)

f

Francis D. [email protected]

Thanks Francis,

here? (Not tested by me.)
f
This did the trick. $uri had /community as the first part but you are
right using
try_files $uri $uri/ /community/index.php?qa-rewrite=$uri&$args;
forced it to use the correct php location and then in the application
removing /community from the $uri (which translates to
$_GET[‘qa-rewrite’]) worked perfectly for me.

Thanks again.
Nikhil