Nginx 404 页面位于哪里 ?

2018-12-14 14:23:19 +08:00
 HarryQu

最近在折腾 Nginx , 想找到这个 404 页面在那里 !

上述的 404 页面并不在 /usr/share/nginx/html 当中

/usr/share/nginx/html 中的 404 页面是这样的 :

在 linux 中执行命令,搜索 nginx/1.12.2,并没有找到这个文件

 find / -xdev -type f -print0 | xargs -0 grep -H "nginx/1.12.2"

因此 ,这个文件在哪里呢 ?

2825 次点击
所在节点    Linux
11 条回复
jinksw
2018-12-14 14:26:21 +08:00
greenskinmonster
2018-12-14 14:29:23 +08:00
msg7086
2018-12-14 14:43:38 +08:00
为了效率。这种常见的返回页面还要靠磁盘文件的话效率太低了。写进源代码一把梭。要修改的话直接改源码重新编译即可。
HarryQu
2018-12-14 14:45:44 +08:00
@greenskinmonster 原来不是直接写在 html 文件里的呀....
HarryQu
2018-12-14 14:46:28 +08:00
@msg7086 原来如此 , Thanks
460881773
2018-12-14 15:48:56 +08:00
你可以自定义 404 页面跳转啊不一定要 重新编译源码
HarryQu
2018-12-14 15:55:21 +08:00
@460881773 因为没有在 /usr/share/nginx/html 下发现这个文件,所以好奇想知道这个文件的路径在哪里。
liyer
2018-12-14 16:00:42 +08:00
创建个 404 丢进去就行了
coolloves
2018-12-14 16:33:57 +08:00
这个 404 是没有实体页面的吧,nginx 返回 4xx 5xx 都是这个界面,
Hardrain
2018-12-15 11:13:14 +08:00
版本号估计会从 c 的 header(.h 文件)获得,而不是硬编码,所以你用 nginx/${版本号}去 grep 应该找不到。
Hardrain
2018-12-15 11:17:30 +08:00
是硬编码的,在$nginx_source_path/src/http/ngx_http_special_response.c 里面。

~ sed -n 132,137p $nginx_source_path/src/http/ngx_http_special_response.c

static char ngx_http_error_404_page[] =
"<html>" CRLF
"<head><title>404 Not Found</title></head>" CRLF
"<body>" CRLF
"<center><h1>404 Not Found</h1></center>" CRLF
;

至于页脚的版本号,应该与同一个文件中的 21,39 行有关
static u_char ngx_http_error_full_tail[] =
"<hr><center>" NGINX_VER "</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;


static u_char ngx_http_error_build_tail[] =
"<hr><center>" NGINX_VER_BUILD "</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;


static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

以上结果由 nginx 1.15.7 源码得出。
你可以下载其源码,修改这个文件后,用 nginx -V 获取原先的编译参数,再重新编译安装。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/517547

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX