Nginx, PHP + FPM Custom Error Pages

前端 未结 1 1274
暗喜
暗喜 2021-01-12 02:42

I am trying to create some custom error pages but can\'t seem to get the 500 one working.

I have the following config:

server {
    listen 80;

    r         


        
相关标签:
1条回答
  • 2021-01-12 03:09

    The piece you're missing is the fastcgi_intercept_errors directive. Without this directive, Nginx won't touch responses from CGI backends, so long as they are valid:

    Determines whether FastCGI server responses with codes greater than or equal to 300 should be passed to a client or be redirected to nginx for processing with the error_page directive.

    You need to put the following in your PHP handling location:

    fastcgi_intercept_errors on;
    

    As an aside, you may not need the = in your error_page lines (depending on your intended use). This syntax instructs Nginx to use the response code returned from the PHP script you're pointing to instead of the original response code:

    If an error response is processed by a proxied server or a FastCGI server, and the server may return different response codes (e.g., 200, 302, 401 or 404) ... respond with the code it returns.

    0 讨论(0)
提交回复
热议问题