index and location not working together properly?

Ian Hobson ian.hobson at ntlworld.com
Fri Jul 26 10:19:45 UTC 2013


Hi all,

Still fighting with my nginx configuration.  What I want to achieve.

If static file exists in "reseller" root,
     serve from "reseller" root
else if  static file file exists in "central" root,
     then serve from "Central" root
else
     reply with 404
endif
If php file exists in "reseller" root,
     serve from "reseller" root via FCGI
else if  php file file exists in "central" root,
     then serve from "Central" root via FCGI
else
     reply with 404
endif
if  no query given
     serve "index.php" according to above rules.
end if

I have got everything working, except the last bit. If index.php exists 
ONLY in the central root,
then I get a 403.  I've tried rewrite. I've tried index. Tried 
"try_files $uri index.php".

Below I have tried a special location to force things - it doesn't work 
either.

Here is my config
#  reseller on anake
#
#     This is the development version - in reseller and served without ssl!
#
server {
     server_name reseller.anake.hcs;
     listen   80;
     fastcgi_read_timeout  300;
     index index.php;
     root /home/ian/websites/reseller/htdocs;
     # if / then redirect to index.php
     location = / {
        # serve /index.php
        rewrite ^$ /index.php last;
     }
     # if local php file exits, serve with fcgi
     location ~ \.php$ {
         try_files $uri $uri/ @masterphp;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include /etc/nginx/fastcgi_params;
     }
     # serve php file from master root
     location @masterphp {
     root /home/ian/websites/coachmaster3dev/htdocs;
     try_files $uri /index.php =404;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include /etc/nginx/fastcgi_params;
     }
     # serve local static files if they exist
     try_files $uri @masterstatic;
     # switch to master set
     location @masterstatic {
         root /home/ian/websites/coachmaster3dev/htdocs;
         try_files $uri =404;
     }
}

reseller.anake.hcs/index.php  results in
     if  reseller/htdocs/index.php exists it is served - correctly
     if  reseller/htdocs/index.php does not exist and 
coachmster3dev/htdocs/index.php exists,  then the coachmaster3 version 
is served - correctly
However
reseller.anake.hcs  results in
     if  reseller/htdocs/index.php exists it is served - correctly
     if  reseller/htdocs/index.php does not exist and 
coachmster3dev/htdocs/index.php exists,  then I get a 403 Forbidden. It 
should serve the coachmater3dev version.

I have checked many times, and there are NO permission problems on 
directories and files.

So what is going wrong.  It appears as if  try_files ??  ?? @somewhere 
;  disables index.

Thanks for your help.

Ian

p.s. Is there an alternate approach that I might try?

-- 
Ian Hobson
31 Sheerwater, Northampton NN3 5HU,
Tel: 01604 513875
Preparing eBooks for Kindle and ePub formats to give the best reader experience.



More information about the nginx mailing list