Welcome! Log In Create A New Profile

Advanced

index and location not working together properly?

Ian Hobson
July 26, 2013 06:22AM
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.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

index and location not working together properly?

Ian Hobson July 26, 2013 06:22AM

Re: index and location not working together properly?

Maxim Dounin July 26, 2013 11:26AM

Re: index and location not working together properly?

Ian Hobson July 26, 2013 03:52PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 103
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 214 on March 20, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready