This is now how alias is supposed to be used. In fact you’re using
alias like a root directive. Using alias is for when you want to use a
certain base directory and don’t want the URI to reflect that.
location /foo {
alias /var/www/nginx-default/barz;
}
Request for /foo/xpto.png is translated to
/var/www/nginx-default/barz/xpto.png
but it does not seem to work, static files load fine.
the php location block is like this and works fine for the main
location block of “location /”
location ~ .php$
{
include fcgi;
fastcgi_pass 127.0.0.1:9000;
}
You should have a fastcgi_pass directive where you want the PHP files
to be handled.
Thanks,
I tried it using “root” in the location, still no luck.
Here’s my config (the parts that matter), the location /nagios/ is what’s
not working. Â What am I doing wrong? Thanks
“not working”?
What are you expecting?
What are you getting?
         index index.php;
     }
as this one is located in different root path, you need additional php
block
Thank you for your suggestion, I remember the vigorous discussion that
took
place regarding this issue, in this particular case, this is a test /
development system so I’m not as concerned as I normally would be.
In our production environment, things are a bit more rigid.
For security reasons I suggest you constrain which exact locations can
be used for FastCGI. Using a generic regex for any file with php
extension opens a big security hole. This was discussed not long ago
on the list.
Instead you should enumerate which files are to be handled by FastCGI
and return a 404 for every other file that is not enumerated. E.g.,
location ~* ^/index.php$ {
include fcgi;
fastcgi_pass 127.0.0.1:9000;
}
And put at the end of the config file:
Any other attempt to access PHP files returns a 404.
Thanks for the advice. Â When I do it this way, I get an error (nginx error
log):
2010/10/03 00:27:33 [error] 20239#0: *6447
“/usr/local/nagios/share/nagios/index.php” is not found (2: No such file or
directory)
so you can see that nginx is adding /nagios/ to the end of the root
directory and so the file is not found (generating a 404 on the browser).
What would be the correct way to address this issue?
location /nagios/
{
root /usr/local/nagios/share;
index index.php;
}
use alias.
location ~ ^/nagios/(.*.php)$ {
alias /usr/local/nagios/share/$1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
location = /nagios {
rewrite ^ /nagios/ permanent;
}
location /nagios/ {
index index.php;
alias /usr/local/nagios/share/;
}