- 創(chuàng)建自己的404.html頁面
- 更改nginx.conf或虛擬主機(jī)的域名.conf在server 區(qū)域加入:
error_page 404 /404.html;
- 測試nginx.conf正確性:
/usr/local/nginx/sbin/nginx -t
如果正確應(yīng)該顯示如下信息:
the configuration file /opt/nginx/conf/nginx.conf syntax is ok
configuration file /opt/nginx/conf/nginx.conf test is successful
- 重啟nginx
/usr/local/nginx/sbin/nginx -s reload
- 注意事項(xiàng)
不要出于省事或者提高首頁權(quán)重的目的將首頁指定為404錯(cuò)誤頁面,也不要用其它方法跳轉(zhuǎn)到首頁。
自定義的404頁面必須大于512字節(jié)昧廷,否則可能會出現(xiàn)IE默認(rèn)的404頁面。例如甚侣,假設(shè)自定義了404.html,大小只有11個(gè)字節(jié)(內(nèi)容為:404錯(cuò)誤)。