[英]Redirect nginx errors to php
我的目標是將nginx中的任何錯誤(即404,405等...)重定向到我位於index.php
php腳本。 `
server {
root /usr/share/nginx/TradeLog/www/;
index index.php index.html index.htm default.html default.htm;
# Make site accessible from http://localhost/
server_name localhost;
server_name_in_redirect off;
fastcgi_intercept_errors on;
error_page 403 404 /index.php/;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.php$
{
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_read_timeout 600; # Set fairly high for debugging
fastcgi_index index.php;
}
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
expires max;
}
}
`
但是,當我嘗試這個時,我遇到了一個nginx 404錯誤。 我在這做錯了什么?
我發現如果我將fastcgi_intercept_errors on
為off
,那么nginx會處理錯誤。 我的下一步是設置一個新的php腳本請求,它將顯示錯誤。 這是位置/errors/code/<code_number>
。
說我有以下位置塊:
location = /composer.phar { return 403; }
我想然后重定向到錯誤頁面/error/code/403
因此,我在想
error_page 403 = /error/code/403;
我會為我做這個伎倆,但是我的php腳本仍在提取原始請求 - 我總是顯示404頁面,因為我的PHP腳本正在獲取一個它不知道的位置的請求。 我希望nginx告訴它哪個頁面在外部顯示,然后只是傳遞錯誤編號的腳本。
我想你應該替換:
error_page 403 404 /index.php/;
有:
error_page 403 404 /index.php;
額外/重定向到目錄,而不是文件。 其余配置似乎沒問題。
這是工作error_page 404 = /index.php;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.