当前位置: 代码网 > it编程>数据库>Mysql > nginx的error_page配置选项详解

nginx的error_page配置选项详解

2025年10月14日 Mysql 我要评论
nginx的error_page配置选项1.语法句法:error_page code ... [=[response]] uri;默认:-内容:http,server,location,if in l

nginx的error_page配置选项

1.语法

句法:	error_page code ... [=[response]] uri;
默认:	-
内容:	http,server,location,if in location

2.跳转其他网站

[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这种的网络地址
#访问linux.web.com报错403、404跳转到百度页面

3.跳转本地文件

[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.访问php文件错误页面跳转

[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;
        }
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com