請教關於nginx配置404錯誤頁面

來源:互聯網
上載者:User
配置如下:

error_page   400 401 402 403 404  /40x.html;location = /40x.html {    root /Library/WebServer/public_html/dev/;}

生效後,訪問下面網頁

  • http://dev.com/u.php 提示:File not found.
  • http://dev.com/abc.html 返回指定的error頁面

請問這是怎麼回事,要怎麼解決?

回複內容:

配置如下:

error_page   400 401 402 403 404  /40x.html;location = /40x.html {    root /Library/WebServer/public_html/dev/;}

生效後,訪問下面網頁

  • http://dev.com/u.php 提示:File not found.
  • http://dev.com/abc.html 返回指定的error頁面

請問這是怎麼回事,要怎麼解決?

(1)檢查server模組裡fastcgiintercepterrors是否開啟,命令

fastcgi_intercept_errors on;

(2)檢查location匹配40x的根目錄是否有404頁面,以及許可權配置
(3)配置完成後,是否reload或者restart nginx伺服器
(4)nginx本身是無法解析php的,所以需要通過fastcgi代理給fpm來解析php檔案,我不寫具體配置了,google即可
(5)php指令碼錯誤,拋出的可能是50x錯誤,你的error_page裡沒有定義

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.