繁体   English   中英

为什么自定义错误页面在我的Nginx配置中不起作用?

[英]Why is Custom Error Page not working in my nginx configuration?

我有以下服务器块:

server {
    listen 80;
    server_name utsav-dev.domain.org;
    root /var/www/domain-utsav-dev/web;
    access_log /var/log/nginx/domain-utsav-dev-access.log;
    error_log  /var/log/nginx/domain-utsav-dev-error.log error;
    error_page 404 = /var/www/domain/web/50x.html;

    set $thttps $https;
    set $tscheme $scheme;
    if ($http_x_forwarded_proto = http) {
      set $thttps off;
      set $tscheme "http";
    }
    if ($http_x_forwarded_proto = HTTP) {
      set $thttps off;
      set $tscheme "http";
    }



    index app.php index.html index.htm;
    try_files $uri $uri/ @rewrite;
    location @rewrite {
        rewrite ^/(.*)$ /app.php/$1;
    }
    # CSS and Javascript
    location ~* \.(?:css|js)$ {
      expires 86400;
      access_log off;
      add_header Cache-Control "public";
    }

    location ~ \.php {
        fastcgi_index app.php;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param APPLICATION "www";
        fastcgi_param APPLICATION_ENV "dev";
    fastcgi_param PDFLIBLICENSEFILE "/etc/php5/fpm/pdflib.license";
        fastcgi_param   HTTPS           $thttps;
    }

    location ~ /\.ht {
        deny all;
    }
   chunked_transfer_encoding off;

}

现在按照脚本,如果未找到页面,nginx应该在内部重定向到50x.html,但是当我尝试打开http://utsav-dev.domain.org/blah.html时,它给我错误“找不到文件”我期望的自定义​​404页面。 为什么?

尝试将fastcgi_intercept_errors on;设置为fastcgi_intercept_errors on; 在您的fastcgi位置。

fastcgi_intercept_errors on | off; 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.

当您访问http://utsav-dev.domain.org/blah.html

  • 首先检查每个位置。 没有人打
  • 它通过try_files 点击@rewrite位置。
  • uri更改为/app.php/blah.html
  • 点击fastcgi位置。

您应该将fastcgi_intercept_errors on;设置为fastcgi_intercept_errors on; error_page工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM