nginx的error_page配置選項(xiàng)詳解
更新時(shí)間:2025年10月14日 14:25:22 作者:backzy
這篇文章主要介紹了nginx的error_page配置選項(xiàng),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
nginx的error_page配置選項(xiàng)
1.語(yǔ)法
句法: error_page code ... [=[response]] uri; 默認(rèn): - 內(nèi)容: http,server,location,if in location
2.跳轉(zhuǎn)其他網(wǎng)站
[root@web01 /etc/nginx/conf.d]# vim linux.web.com.conf
server {
listen 80;
server_name linux.web.com;
location / {
root /code/web;
index index.html;
error_page 403 404 http://www.baidu.com;
}
}
#error_page配置的是http這種的網(wǎng)絡(luò)地址
#訪問(wèn)linux.web.com報(bào)錯(cuò)403、404跳轉(zhuǎn)到百度頁(yè)面
3.跳轉(zhuǎn)本地文件
[root@web01 /etc/nginx/conf.d]# vim linux.web.com.conf
server {
listen 80;
server_name linux.web.com;
location / {
root /code/web;
index index.html;
error_page 403 404 /404.jpg;
}
}
4.訪問(wèn)php文件錯(cuò)誤頁(yè)面跳轉(zhuǎn)
[root@web01 /etc/nginx/conf.d]# vim linux.web.com.conf
server {
listen 80;
server_name linux.web.com;
root /code/web;
index index.php;
error_page 404 403 /404.html;
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if (!-e $request_filename) {
rewrite (.*) http://linux.web.com/404.jpg;
}
}
}
5.完整配置
[root@zzc /blog/wordpress]# vim /etc/nginx/conf.d/wordpress.conf
server {
listen 80;
server_name localhost;
root /blog/wordpress;
location / {
index index.php;
error_page 403 404 /404.jpg;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if (!-e $request_filename){
rewrite (.*) http://zzcblog.top/404.jpg;
}
}
location ~* \.(jpg|png)$ {
root /blog/wordpress;
error_page 403 404 /404.jpg;
}
}
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
nginx動(dòng)態(tài)添加訪問(wèn)白名單的方法
本篇文章主要介紹了nginx動(dòng)態(tài)添加訪問(wèn)白名單的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-02-02
詳解Nginx中的Rewrite的重定向配置與實(shí)踐
這篇文章主要介紹了詳解Nginx中的Rewrite的重定向配置與實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
Nginx+ModSecurity安全模塊部署的實(shí)現(xiàn)
本文主要介紹了Nginx+ModSecurity安全模塊部署的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
如何修改Nginx版本名稱(chēng)偽裝任意web server
這篇文章主要介紹了修改Nginx版本名稱(chēng)偽裝任意web server的方法,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-08-08
使用nginx進(jìn)行負(fù)載均衡的搭建全過(guò)程
負(fù)載均衡用于從“upstream”模塊定義的后端服務(wù)器列表中選取一臺(tái)服務(wù)器接受用戶的請(qǐng)求,下面這篇文章主要給大家介紹了關(guān)于使用nginx進(jìn)行負(fù)載均衡的搭建全過(guò)程,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08

