Nginx默认是显示版本号的,如:
[[email protected] ~]# curl -I www.yuminstall.com HTTP/1.1 200 OK Server: nginx/1.4.7 Date: Mon, 04 Aug 2014 09:28:55 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.3.28 X-Pingback: http://www.yuminstall.com/xmlrpc.php
这样就给人家看到你的服务器nginx版本是1.4.7,前些时间暴出了一些Nginx版本漏洞,就是说有些版本有漏洞,而有些版本没有。这样暴露出来的版本号就容易变成攻击者可利用的信息。所以,从安全的角度来说,隐藏版本号会相对安全些!
隐藏Nginx的版本号和隐藏php的版本号原理一样 通过程序的参数来控制
1、进入nginx配置文件的目录
[[email protected] ~]# cd /usr/local/nginx/conf/
这是Nginx默认安装后的路径
2:编辑nginx.conf文件;这个文件就是Nginx的主配置文件
[[email protected] conf]# vim nginx.conf
3:在配置文件里加入server_tokens off; 参数;这个参数可以加到http {—}里;也可以加到server {—}里;放在不同的地方效果不一样而已;
http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; server_tokens off; sendfile on; tcp_nopush on; keepalive_timeout 0; keepalive_timeout 65; gzip on;
4:然后检查配置是否有错误
[[email protected] conf]# /usr/local/nginx/sbin/nginx -t
5:如果没有错误就可以重启Nginx服务后来查看效果
6:最后的结果:
[[email protected] conf]# curl -I www.yuminstall.com HTTP/1.1 200 OK Server: nginx Date: Fri, 18 Jul 2014 03:54:48 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding
至此一个简单的Nginx隐藏版本号的操作就此完成。