nginx

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > nginx > nginx的error_page配置选项

nginx的error_page配置选项详解

作者:backzy

这篇文章主要介绍了nginx的error_page配置选项,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文