首页 > 代码库 > nginx指定404错误页面跳转

nginx指定404错误页面跳转

需求:

    wKiom1SFIVXCUvg1AAGuMaUK6bI246.jpg

修改配置文件进行跳转:

    

server {
        listen       80;
        server_name shadouyou.com www.shadouyou.com;
            if ($host = ‘shadouyou.com‘ ) {
        rewrite ^/(.*)$ http://www.shadouyou.com/$1 permanent;
                }
        root   /Disk/var/www/index;
        include /etc/nginx/conf.d/shadouyou-SEO;
        location / {
                index  index.html index.htm;
                        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 ( !-e $request_filename ) {
                        proxy_pass      http://index;
                }
                if ($request_uri ~* newsinfor.*) {
                        rewrite ^(.*)$ /404.html last ;
                }
        }
        error_page 404  /404.html;
        location = /404.html {
                root   /usr/share/nginx/html;
        }

当客户端访问www.shadouyou.com/newsinfor_XXXX.html的时候被最后一个if拦截重写到下面的404.html的location中 在root目录下上传一个自己写好的404的html文件即可

本文出自 “精忠报国” 博客,谢绝转载!

nginx指定404错误页面跳转