I'm trying to configure Nginx to send ALL 404s to a php file for futher processing. I have not got it working. With try_files I get a default 404 and without try_files I get no input file specified. This is what I have so far:
server {
listen 192.168.100.44:80;
location / {
index index.html;
}
root /var/www/test.example.com;
error_page 404 /404.php;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#try_files $uri = 404;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The answer was to add the line: fastcgi_intercept_errors on;
Then, in order to handle the 404 and possibly return a different status code from the PHP script: error_page 404 /404.php; Had to simply be changed to: error_page 404 = /404.php;
Credit to the kind people in the Nginx IRC channel who took a few moments of their time to show me the right direction.
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