Nginx优雅显示错误页面

 

1.跳转到网上

#error_page配置的是http这种的网络地址
[root@web01 conf.d]# cat error.conf 
server {
    listen       80;
    server_name  linux.error.com;

    location / {
        root /code/error;
        index index.html;
        error_page 404 http://www.baidu.com;
    }
}

 

2.跳转本地文件

[root@web01 /code/error]# vim /etc/nginx/conf.d/error.conf
server {
    listen 80;
    server_name  linux.error.com;

    location / {
        root /code/error;
        index index.html;
        error_page 404 403 /404.jpg;
    }
}

 

3.访问PHP的错误页面跳转

[root@web01 /code/error]# vim /etc/nginx/conf.d/error.conf
server {
    listen 80;
    server_name  linux.error.com;
    root /code/error;
    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.error.com/404.jpg;
        }
    }
}

 

posted @ 2020-09-11 16:07  六月OvO  阅读(384)  评论(0编辑  收藏  举报