簡體   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