隐藏HTTP请求响应头里的nginx版本号

2015年4月11日10:12:42网站建设评论1,818

搭建好nginx后,为了安全起见,我们都会想办法隐藏nginx的版本号。由于针对网络上经常爆出针对特定版本nginx的漏洞,将版本号隐藏好,可以有效的防止服务器被黑。文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

查看服务器是否显示nginx默认版本号:文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

curl -I www.123456.com文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

HTTP/1.1 200 OK
Server: nginx/1.2.9
Date: Sat, 11 Apr 2015 01:55:36 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

这样很容易暴漏自己使用的是nginx1.2.9版本,别有用心的人就可以根据此版本的漏洞发起一些攻击。为了服务器安全你可以通过以下方法隐藏nginx版本号:文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

1、进入nginx配置文件(如nginx.conf)并增加 server_tokens off;server_tokens作用域是http server location语句块,server_tokens默认值是on,表示显示版本信息,设置server_tokens值是off,就可以在所有地方隐藏nginx的版本信息。例如文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

http {
……省略
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
…….省略
}文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

2、编辑php-fpm配置文件,如fastcgi.conf或fcgi.conf(这个配置文件名也可以自定义的,根据具体文件名修改):文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

找到:
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
改为:
fastcgi_param SERVER_SOFTWARE nginx;文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

3、重启nginx 重新加载配置文件后,nginx版本号已经隐藏。文章源自堕落的鱼-https://www.duoluodeyu.com/1274.html

匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定