I have a PHP-FPM configured as backend for nginx 1.1.15. I need to customize 40x, 50x error pages for errors coming from PPH-FPM.
For example, I send 403 header from php script and want nginx to show custom page.
nginx configured as follows:
error_page 403 /403.html;
location = /403.html {
root html;
allow all;
}
But when I send 403 header from php, nginx shows it's native "403 Forbidden" page, not my custom.
Upd: I'm sorry. I didn't give full config of nginx. I handle 404 in nginx and pass all queries to a single script. This script sends 403 headers. So nginx not display custom 403 page. When I request an existing script, to bypass the 404 rule in nginx conf, then custom error page is returned. Here is a part of my nginx.conf
error_page 404 = @myhandler;
location @myhandler {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME script.php;
include fastcgi_params;
}
error_page 403 /403.html;
location = /403.html {
root html;
allow all;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
}
UPD: I've found a solution.
**recursive_error_pages on;**
error_page 404 = @myhandler;
location @myhandler {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME script.php;
include fastcgi_params;
**error_page 403 /403.html;**
}