1. 程式人生 > 實用技巧 >Nginx優雅顯示錯誤頁面

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