I'm configuring a pretty standard webserver using nginx. The server is working as expected, however, there is a small configuration detail I would like to understand.
My current configuration is:
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?q=$uri;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
With this configuration, if I access to: http://myweb.com/wp-content/uploads/2012/10/cropped-bitmap11.png/lol.php I get a 404 as expected.
However, with this configuration:
try_files $uri =404;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
I get a blank page with "Access denied".
Why is the result different?
Thank you
You are probably under the impression that try_files
on server level must work for every request. Not at all. Quite the contrary, it works only for requests that match no location
blocks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With