nginx隐藏版本信息,nginx版本信息


1.源码编译安装一份nginx
tar xzf nginx-1.11.9.tar.gz
cd nginx-1.11.9
./configure --prefix=/usr/local/nginx
make && make install

2.启动nginx
/usr/local/nginx/sbin/nginx

3.查看nginx的版本信息
curl -I 192.168.146.134 #ip改为你自己的
如果nginx安装正确,并正常启动会看到下面的信息:
HTTP/1.1 200 OK
Server: nginx/1.11.9
Date: Sun, 05 Feb 2017 07:51:01 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 05 Feb 2017 07:48:23 GMT
Connection: keep-alive
ETag: "5896d8c7-264"
Accept-Ranges: bytes

斜体字部分标明了你所用的WEB服务器的名称和版本信息,在生产环境中暴露这些信息是不安全的。通过两种方式对上述信息进行隐藏:
一是在配置文件中加入server_tokens off;参数禁止版本信息泄漏:
再次查看web server版本信息
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 Feb 2017 08:05:33 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 05 Feb 2017 07:48:23 GMT
Connection: keep-alive
ETag: "5896d8c7-264"
Accept-Ranges: bytes

这种情况下只能隐藏版本,不能隐藏文件名。
第二种办法是在编译的时候把源文件里的版本信息更改一下,编译完后显示的是你修改的内容。
修改源码包里的三个文件:
1.src/core下的nginx.h文件
#define nginx_version 100011
#define NGINX_VERSION "7.89"
#define NGINX_VER "GWS/" NGINX_VERSION
2.src/http下的ngx_http_header_filter_module.c文件
static char ngx_http_server_string[] = "Server: GWS" CRLF;
3.src/http下的ngx_http_special_response.c文件
static u_char ngx_http_error_tail[] =
"<hr><center>GWS</center>" CRLF

重新编译nginx:
make clean
./configure --prefix=/usr/local/nginx
make && make install

重新启动nginx后再次查看一下
HTTP/1.1 200 OK
Server: GWS
Date: Sun, 05 Feb 2017 08:33:58 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 05 Feb 2017 08:24:02 GMT
Connection: keep-alive
ETag: "5896e122-264"
Accept-Ranges: bytes

server的输出内容变成了我自己改的名称。

相关内容

    暂无相关文章