nginx + fastCGI for PHP error_page

隐身守侯 提交于 2021-02-10 07:06:48

问题


I set up custom error pages in nginx with fastCGI for PHP like this way and it works:

root <FOLDER>;
error_page 404 /error.php?404;
location = /error.php {
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass  127.0.0.1:1234;
    root  <FOLDER>;
}

But since I have one error.php for every HTTP error codes, I wanted to set up in a general form. The problem is that I don't know if nginx provide the error code to be passed by GET to error.php

I am looking for something like:

root <FOLDER>;
error_page 500 501 502 401 402 403 404 /error.php?NGINX_ERROR_CODE;
location = /error.php {
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass  127.0.0.1:1234;
    root  <FOLDER>;
}

The problem is NGINX_ERROR_CODE which I don't know if it provides such a thing to set up general error_page handler.

Is it any way?


回答1:


Googling around, it doesn't initially appear that there's a var for it.

You can, however, set multiple error page directives.

error_page 401 /error.php?e=401;
error_page 402 /error.php?e=402;
error_page 403 /error.php?e=403;
error_page 404 /error.php?e=404;
error_page 500 501 502 /error.php?e=50x;

and so on.



来源:https://stackoverflow.com/questions/10739436/nginx-fastcgi-for-php-error-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!