gpt4 book ai didi

没有重定向的 NGINX 自定义 404 页面

转载 作者:行者123 更新时间:2023-12-03 17:08:55 30 4
gpt4 key购买 nike

默认情况下,当 NGINX 返回 404 时,它会呈现一些默认的 HTML。例如,类似于:

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.0 (Ubuntu)</center>
</body>
</html>

我想自定义此 HTML 但保持 URL 不变。我试过为 404s 设置错误页面:
error_page 404 /404.html

但这首先将浏览器重定向到 /404.html .

有没有办法在不重定向的情况下自定义 404 HTML?

最佳答案

这个配置对我有用

error_page 404 /404.html;
location = /404.html {
internal;
}

http://nginx.org/en/docs/http/ngx_http_core_module.html#internal

关于没有重定向的 NGINX 自定义 404 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39885759/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com