有時候爲了安全,我們需要在新安裝好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