Redirect nginx errors to php
nginx, php
Solution
I think you should replace:
error_page 403 404 /index.php/;
with:
error_page 403 404 /index.php;
The extra / make the redirection to a directory, not to a file. The rest of your configuration seems to be ok.
Problem
My aim is to have any error in nginx (i.e. 404, 405 etc...) be redirected to my php script located at `index.php`. ` ``` server { root /usr/share/nginx/TradeLog/www/; index index.php index.html index.htm default.html default.htm; # Make site accessible from http://localhost/ server_name localhost; server_name_in_redirect off; fastcgi_intercept_errors on; error_page 403 404 /index.php/; location / { try_files $uri $uri/ /index.php?$args; } location ~* \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_read_timeout 600; # Set fairly high for debugging fastcgi_index index.php; } location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { expires max; } } ``` ` However, when I attempt this, I am greeted with an nginx 404 error. What am I doing wrong here? EDIT I have found that if I turn `fastcgi_intercept_errors on` to `off`, then nginx deals with the errors. My next step is to then set a new request for the php script which will display errors. This is at the location `/errors/code/<code_number>`. Say I had the following location block: `location = /composer.phar { return 403; }` I want to then redirect to the error page at `/error/code/403` Therefore, I was thinking `error_page 403 = /error/code/403;` would do the trick for me, but my php script is still picking up the original request - I always show a 404 page because my PHP script is getting a request for a location that it doesn't know. I want nginx to tell it which page to display externally and then just pass the scrip the error number.