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
阅读 1299 · 发布于 2021-05-12
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
JMeter 使用 Response Assertion 判断接口请求是否成功阅读 1756
-
JavaScript/PHP 判断是否为微信内置浏览器阅读 2922
-
npm install --save 和 --save-dev 的区别阅读 1090
-
macOS 打开 Eclipse Memory Analyzer 直接闪退解决方法阅读 92
-
Linux LC_ALL=C 的作用阅读 792
-
软考-系统架构设计师:数据仓库与数据挖掘阅读 1876
-
Java 使用 FutureTask 解决缓存击穿(缓存踩踏)问题阅读 3030
-
SQL Server 修改计算机名后修改服务名阅读 1537
-
Spring Boot 代码中生成 MultipartFile 对象阅读 264
-
Arthas 使用 monitor 在指定时间段内统计方法的调用次数、平均返回时间等阅读 3275