nginx隐藏响应头server_错误页面版本号

原由

今天在维护公司的老项目时,担心Server显示的nginx/1.16.0信息会暴露信息,给不良分子利用。于是想要隐藏。

网上说法

在nginx.conf,的http上添加server_tokens off;

【结果】

不起作用,nginx还是返回了版本信息。

【原因】

低版本的nginx设置server_tokens off不起作用,高版本的可以。到底多高的可以,没有进行验证。因为我另一台1.2x.x是可以正常隐藏版本号的,但是还是会显示nginx字样。我公司nginx/1.16.0版本是不起作用的,网上有人反馈,nginx/1.10.1也是不起作用的。

nginx隐藏响应头server终极办法

在编译安装前修改nginx源码。

1、源码位置,大概在13行的位置是版本号,14行的位置是nginx标识。

cd /home/nginx-1.23.0
vim src/core/nginx.h

2、修改 ngx_http_special_response.c 和 ngx_http_header_filter_module.c 两个文件,这两个文件在http包下。

(1) ngx_http_special_response.c 修改22, 29, 36行。三处全部修改为myserver,22行和29行要把引号去掉。

cd /home/nginx-1.23.0
vim src/http/ngx_http_special_response.c

【修改前】

【修改后】

(2)ngx_http_header_filter_module.c 修改49行

cd /home/nginx-1.23.0
vim src/http/ngx_http_header_filter_module.c

3、编译安装——————完成。

点击显示
· JS时间戳和时间之间转换_时间戳js转换_获取时间戳js
· Uncaught TypeError: this.$http is undefined
· You are running a development build of Vue.
· jquery on方法_jquery从哪个版本开始支持on方法
· Uncaught TypeError: $(...).on is not a function