自己定义404 页面,通过 nginx 配置一下,重新定向
1. http 里面添加配置
proxy_intercept_errors on; fastcgi_intercept_errors on;
2. server 中添加配置
error_page 500 502 503 504 /404.html;
error_page 404 /404.html;
location = /404.html {
# 404 页面的目录
root /usr/local/nginx/html;
# root D:/work/ATMs/nginx/html;
}
整个nginx 配置文件 示例:
user nginx;
worker_processes auto;
error_log ../nginx/logs/error.log;
pid ../nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
access_log ../nginx/logs/access.log;
proxy_intercept_errors on;
fastcgi_intercept_errors on;
sendfile on;
keepalive_timeout 65;
server {
listen 800;
server_name localhost;
root ..//web-app//dist;
location / {
index index.html;
}
error_page 500 502 503 504 /404.html;
error_page 404 /404.html;
location = /404.html {
# 404 页面的目录
root /usr/local/nginx/html;
# root D:/work/ATMs/nginx/html;
}
location /api/ {
proxy_pass http://127.0.0.1:91/service/app/;
proxy_cookie_path /service /;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300s;
proxy_send_timeout 30s;
proxy_read_timeout 300s;
add_header X-Frame-Options SAMEORIGIN;
}
}
}
二、网上找的几个404 页面示例
直接拷贝到 html 里面就可以
WAP Websites - Site Error Error 404 - Web Site not found!
The site you have attempted to reach is not available.
404页面 <!DOCTYPE html> <html> <style> * { everything:awesome; } </style> <body> ERROR 404! FILE NOT FOUND! <!--The file you are looking for, is not where you think it is.-->
</body>
</html>