nginx 定义502 404 错误提示页面

nginx 与后端 web server 是分开的,二台服务器
 
192.168.1.11   Nginx
192.168.1.12   Web server
 
定义nginx 404  502错误提示页面,直接配置nginx 502错误,找了很多资料,最终没能实现。下面用另一个方法实现.
 

方法一、

在nginx.conf配置文件里加上以下红色代码
 
erver
                {
                            listen    80;
                            server_name www.tt.com;

                            location / { 
                                     proxy_pass       http: //week; 
                                     proxy_set_header     Host                        $host; 
                                    proxy_set_header     X-Real-IP                $remote_addr; 
                                     proxy_set_header     X-Forwarded-For    $proxy_add_x_forwarded_for; 
               if (!-f $request_filename) { 
                               proxy_pass    http://127.0.0.1:8888; 
                                                               }
                            }
17.0.0.1:8888配置如下
erver
                                {
                                                listen    8888;
                                                server_name www.tt.com;
                                                location / {
                                                root /root;
                                                index index.html;
                                                error_page 500 502 404 /404.html;
                                                                 }

                                }
需要维护的时候,只需要重启nginx服务。
kill -HUP 'cat logs/nginx.pid'

方法二、

单独创建一个testnginx.conf文件
 
#user    nobody;
worker_processes    1;
pid                logs/nginx.pid;

events {
        use epoll;
        worker_connections    50000;
                }

http {
        include             mime.types;
        default_type    application/octet-stream;
        sendfile                on; 
                server
                                {
                                                listen    80;
                                                server_name www.tt.com;
                                                location / {
                                                root /root;
                                                index index.html;
                                                error_page 500 502 404 /404.html;
                                                                 }

                                }
}
维护时只需把nginx停止,从新启用新的配置文件
killall -9 nginx
nginx -c ../conf/testnginx.conf