以前都没有注意到,使用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