【发布时间】:2020-12-09 08:25:03
【问题描述】:
我正在尝试制作自定义 404 页面。
这是我的 404.html:
<html>
<head>
<meta charset="UTF-8">
<title>Not Found</title>
</head>
<body>
<div style="...">
<div style="...">404</div>
<div style="...">Page not found</div>
<img src="404.gif" alt="not found" />
</div>
</body>
</html>
它工作(几乎),但我总是在尝试加载 404.gif 时收到“未找到”错误
这是我的 nginx 配置(只想让 localhost/main/data 和 localhost/main/test 路径可用):
http {
server {
listen 80;
server_name localhost;
error_page 404 /404.html;
location = /404.html {
root /var/www/error/;
}
location /404.gif {
root /var/www/error/;
}
location ~ ^/main/(data|test)$ {
}
当我尝试访问像 http://localhost/main/error_page 这样的任何页面时,服务器返回没有 gif 的自定义 404 页面和错误 GET http://localhost/main/404.gif 404 (Not Found)。
如何加载我的 gif,我需要在 html 中提供什么路径或如何更改配置?
【问题讨论】:
-
检查
/var/log/nginx/errors.log中的错误,它会告诉你它试图从哪里获取图像,从那里开始调试
标签: html nginx nginx-config