我剛剛開始使用Nginx,並做了關於配置PHP FPM的基本配置,並且我已將索引文件更改爲index.php
而不是index.html
。我也成功地處理了URL重寫問題,但爲了簡單起見,我在下面的示例中省略了它。自定義404頁面不顯示
但是在默認配置文件中,有一個專用於錯誤頁面的部分,看起來好像它已準備好「即插即用」。我已取消註釋他們,但他們無法正常工作。我已經經歷了一些關於Stackoverflow的404相關問題,每個人似乎都建議將它作爲正確的語法。
也許指令的順序是錯誤的,但是,這個是從原始示例配置,所以我不知道爲什麼它不會工作。
我已經刪除從配置文件中的所有註釋行,還剩下些什麼,這是:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php;
server_name localhost;
location/{
try_files $uri $uri/ index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
現在,當我去http://localhost/this-page-doesnt-exist
,瀏覽器顯示文字File not found.
,而不是我的/404.html
內容文件。
此外,我的404.html
文件的權限與index.php
(即644)的權限相同。擁有者也是如此。
什麼可能是錯的?