抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

简单记录一下如何将 nginx 404 页面重定向为 404.html

Step. 1 打开配置文件

查看配置文件路径

1
systemctl status nginx.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
● nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since Mon 2022-05-30 14:30:24 CST; 5h 41min ago
Docs: https://nginx.org/en/docs/
Process: 15035 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Process: 15038 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Main PID: 15036 (nginx)
Tasks: 2 (limit: 2340)
Memory: 5.2M
CPU: 34.140s
CGroup: /system.slice/nginx.service
├─15036 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─15037 nginx: worker process

Process: 15035 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf 看出配置文件地址

编辑配置文件

1
vim /etc/nginx/nginx.conf

Step. 2 添加404页面

http中添加

1
fastcgi_intercept_errors on;

server里添加

1
error_page   404    /404.html;

Step. 3 重启

1
systemctl restart nginx.service

评论