WDCP访问不存在的路径全部跳转到首页不返回404的解决办法

以前都没有注意到,使用wdcp面板,nginx引擎,如果访问一个不存在的url它不会返回404,而是自动返回首页,感觉有点坑,所以我们还是要自定义一个404页面的

先把准备好的404.html文件上传到服务器,记录pwd查看绝对路径,然后编辑nginx的配置文件,路径是

vi  /www/wdlinux/nginx-1.16.1/conf/vhos/00000.default.conf

配置文件的扩展名是.conf,上面的路径的nginx版本和conf文件名根据自己的实际情况改变,因为我安装的是1.16.1版本的nginx,所以文件夹命名是nginx-1.16.1

server {
        listen       80;
        root /www/web/default;
        server_name localhost;
        index  index.html index.php index.htm;
        
		location ^~ /icy_pocket/ {
            proxy_pass http://127.0.0.1:8081;
            proxy_set_header Host $host;
        }
        location ^~ /website/ {
            proxy_pass http://127.0.0.1:8081;
            proxy_set_header Host $host;
        }
        # 自定义404页面
        location = /404.html {
            # 把上传的404.html文件路径填写到这
            root   /www/web/default;
        }
	
		error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  503 /errpage/503.html;
        location ~ \.php(.*)$ {
                fastcgi_pass  unix:/tmp/php-73-cgi.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;
                fastcgi_param PATH_INFO $2;
                include fcgi.conf;
        }
        location ~ /\.ht {
                deny  all;
        }
        location / {
                # try_files $uri $uri/ /?$args;
        }
}

server {
        listen       443;
        root /www/web/default;
        ssl                  on;
        ssl_certificate      cert/default.pem;
        ssl_certificate_key  cert/default.key;
        ...
        server_name localhost;
        index  index.html index.php index.htm;
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  503 /errpage/503.html;
        
		location ^~ /icy_pocket/ {
            proxy_pass http://127.0.0.1:8081;
            proxy_set_header Host $host;
        }
        location ^~ /website/ {
            proxy_pass http://127.0.0.1:8081;
            proxy_set_header Host $host;
        }
        # 自定义404页面
        location = /404.html {
            # 把上传的404.html文件路径填写到这
            root   /www/web/default;
        }

		location ~ \.php(.*)$ {
                fastcgi_pass  unix:/tmp/php-73-cgi.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;
                fastcgi_param PATH_INFO $2;
                include fcgi.conf;
        }
        location ~ /\.ht {
	            deny  all;
	    }
        location / {
                # try_files $uri $uri/ /?$args;
        }
}

保存之后记得重启nginx

/www/wdlinux/nginx-1.16.1/sbin/nginx -t
/www/wdlinux/nginx-1.16.1/sbin/nginx -s reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰冷的希望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值