Nginx(OpenResty) 去掉默认错误页面中的版本号
Nginx OpenResty License 大约 1757 字说明
修改Nginx
的源码才能去除,所以必须通过编译安装,yum
或apt-get
方式无法修改。
适用于OpenResty
。
Nginx
和OpenResty
的开源协议为BSD-2-Clause
,所以修改后可以不开源修改部分的代码。
查找页面位置
错误页面是硬编码在ngx_http_special_response.c
文件中。
寻找文件位置:
locate ngx_http_special_response.c
Nginx
路径如下:
nginx-1.19.3/src/http/ngx_http_special_response.c
OpenResty
路径如下:
openresty-1.19.3.1/bundle/nginx-1.19.3/src/http/ngx_http_special_response.c
修改源码
在ngx_http_special_response.c
文件的22
和29
行,可在vim
中使用:n
(n
为行数)跳转至如下代码,或搜索NGINX_VER
关键词。
将NGINX_VER
和NGINX_VER_BUILD
替换为自己想要的字符串,或者删除也可以。
修改前代码:
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_full_tail[] =
"<hr><center>hello world</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
static u_char ngx_http_error_build_tail[] =
"<hr><center>hello world 123</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
修改后代码(去除Nginx
名称和版本号):
static u_char ngx_http_error_full_tail[] =
"</body>" CRLF
"</html>" CRLF
;
static u_char ngx_http_error_build_tail[] =
"</body>" CRLF
"</html>" CRLF
;
OpenResty
还多了如下代码(未改动前第36
行):
static u_char ngx_http_error_tail[] =
"<hr><center>openresty</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
去除后代码:
static u_char ngx_http_error_tail[] =
"</body>" CRLF
"</html>" CRLF
;
备注
OpenResty
的错误页面源码路径如下
openresty-1.19.3.1/build/nginx-1.19.3/src/http/ngx_http_special_response.c
源码
https://github.com/nginx/nginx/blob/branches/default/src/http/ngx_http_special_response.c#L21
阅读 1512 · 发布于 2021-05-12
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
使用 Packer.js 压缩 HTML 和 JavaScript阅读 12361
-
软考-系统架构设计师:层次化存储结构阅读 1559
-
算法:无重复字符的最长子串阅读 1026
-
Spring Boot JPA 打印 SQL 语句及参数阅读 1998
-
Maven 常用命令阅读 268
-
Rust 标准库 API Result阅读 295
-
OpenResty 解析 JSON 中的 null 字段时问题阅读 2591
-
软考-系统架构设计师:规范化理论-价值与用途阅读 2194
-
Kubernetes ConfigMap 创建失败 cannot unmarshal number into Go struct field ConfigMap.data of type string阅读 2425
-
Linux 根据一个文件内容查找另一个文件中的内容阅读 7796