说明:
查看 head 可以看到服务器的nginx,php信息,如下
[root@gaingreat ~]# curl --head www.gaingreat.com HTTP/1.1 200 OK Server: nginx/1.1.19 Date: Thu, 21 Feb 2013 09:12:48 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding X-Powered-By: PHP/5.3.10 X-Pingback: http://www.gaingreat.com/wordpress/xmlrpc.php Vary: User-Agent,Accept-Encoding
可以通过改nginx.conf,php.ini来隐藏这些内容。
实现:
1.隐藏nginx版本信息
a.编辑nginx.conf配置文件,在http{}内增加如下一行
http {
……
server_tokens off;
……
}
b.编辑php-fpm配置文件,fastcgi.conf或fcgi.conf,找到:
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
改为:
fastcgi_param SERVER_SOFTWARE nginx;
c.重启nginx服务生效,可以看到已经没有nginx版本信息。
[root@gaingreat ~]# curl --head x.x.x.x [root@gaingreat ~]# curl --head www.gaingreat.com HTTP/1.1 200 OK Server: nginx Date: Thu, 21 Feb 2013 09:15:59 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding X-Pingback: http://www.gaingreat.com/xmlrpc.php
2.隐藏php版本信息
修改php.ini文件,找到:
expose_php = On
修改为:
expose_php = Off
这样就可以避免http头部信息中返回“X-Powered-By: PHP/5.2.17”字样。。
附录:
apache隐藏头部版本信息(未试)
编辑httpd.conf文件,找到:
ServerTokens OS
ServerSignature On
修改为:
ServerTokens ProductOnly
ServerSignature Off
另:可更改源码include目录下ap_release.h这个文件
#define AP_SERVER_BASEVENDOR “Apache Software Foundation” #apache相关字样都可更改
#define AP_SERVER_BASEPROJECT “Apache HTTP Server”
#define AP_SERVER_BASEPRODUCT “Apache”
#define AP_SERVER_MAJORVERSION_NUMBER 2 #版本字段可随意更改
#define AP_SERVER_MINORVERSION_NUMBER 2
#define AP_SERVER_PATCHLEVEL_NUMBER 17
#define AP_SERVER_DEVBUILD_BOOLEAN 0