日期:2014-05-16  浏览次数:21067 次

nginx及apache版本号隐藏

有时候为了安全,我们需要在新安装好nginx及apache服务器后,隐藏起版本号,这样可以防止针对版本号发起的漏洞攻击,具体操作如下:

一:apache版本号隐藏:

1. 修改apache主配置文件 httpd.conf 将以下信息前面的注释,# 去掉:

# Various default settings
#Include conf/extra/httpd-default.conf

2. 修改 conf/extra/httpd-default.conf ,更正如下信息:

ServerTokens Full 更改为 ServerTokens Prod

ServerSignature On 更改为 ServerSignature Off

3. 重启apache

/opt/soft/apache/bin/apachectl -k restart


二:nginx版本号隐藏:

首先执行 curl -I www.nginx.org ,查看网站的信息情况:

[root@localhost extra]# curl -I www.nginx.org
HTTP/1.1 301 Moved Permanently
Server: nginx/1.5.3
Date: Mon, 21 Oct 2013 03:22:48 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Keep-Alive: timeout=15
Location: http://nginx.org/


红色字体部分显示了 nginx 的版本信息,对于一些版本的nginx来说,是存在漏洞的,为了防患于未然,这里将nginx版本号隐藏,具体操作如下:

1. 编辑nginx主配置文件 nginx.conf ,在 http {} 块中增加如下信息:

http {
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
}

2. 编辑php-fpm配置文件,如fastcgi.conf或fcgi.conf

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

3. 重新加载 nginx 配置 

/etc/init.d/nginx reload