隐藏nginx版本号

执行curl --head www.nginx.org获得如下输出:

HTTP/1.1 200 OK
Server: nginx/0.8.50
Date: Tue, 07 Sep 2010 04:14:16 GMT
Content-Type: text/html
Content-Length: 11699
Last-Modified: Thu, 02 Sep 2010 15:01:30 GMT
Connection: keep-alive
Keep-Alive: timeout=15
Accept-Ranges: bytes

这样,别人就知道你的服务器nginx版本是0.8.50。现在,我们要让它不显示nginx的版本号。

首先,修改nginx.conf文件,内容如下:

http {
  ......省略配置
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  server_tokens off;
  .......省略配置
}

然后,找到fastcgi_params文件,我的是放在/usr/local/nginx/conf目录下,修改该文件,内容如下:

将
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
改为
fastcgi_param  SERVER_SOFTWARE    nginx;

nginx重新加载配置就完成了,404、501等页面都不会显示nginx版本了。

现在,再执行curl --head www.nginx.org获得如下输出:

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 07 Sep 2010 04:14:16 GMT
Content-Type: text/html
Content-Length: 11699
Last-Modified: Thu, 02 Sep 2010 15:01:30 GMT
Connection: keep-alive
Keep-Alive: timeout=15
Accept-Ranges: bytes

猜你喜欢

转载自eric-gao.iteye.com/blog/784680