隐藏响应头Server中Apache、nginx、PHP的版本信息

默认服务器设置HTTP响应头会包含Apache,Nginx和php版本号。这样做会很不安全,因为会让不法分子通过详细的版本号而发起已知该版本的漏洞攻击。4A304AA4-C7BE-421f-BE44-E3CBE2213763.jpg

因此,需要对这部分敏感的信息做隐藏。

一、Apache

在httpd.conf文件中设置ServerTokens的值为Prod,设置ServerSignature的值为Off。如果使用版本不带这个开关,可直接在文件末尾添加即可。

vim /etc/httpd/conf/httpd.conf
ServerTokens Prod
ServerSignature Off

重启Apache服务,这会在响应头中显示“Server:Apache”而不包含任何的版本信息

下面是ServerTokens的一些可能的赋值:

ServerTokens Prod  显示“Server: Apache”
ServerTokens Major 显示 “Server: Apache/2″
ServerTokens Minor 显示“Server: Apache/2.2″
ServerTokens Min   显示“Server: Apache/2.2.17″
ServerTokens OS    显示 “Server: Apache/2.2.17 (Unix)”
ServerTokens Full  显示 “Server: Apache/2.2.17 (Unix) PHP/5.3.5″

二、Nginx

1、在nginx.conf配置文件的http字段中加入server_tokens off

vim /etc/nginx/nginx.conf
server_tokens off;  //隐藏版本号

2、重启Nginx服务,这会在响应头中显示“Server:Nginx”而不包含任何的版本信息,而且nginx自己的404页面也没有版本号的信息。

3、返回自定义的server字段

如果你不希望别人知道你使用什么Server,但又没有办法去隐藏它,所以我们需要去更改,采用编译源码的方法来改变返回的Server,修改src/http/ngx_http_header_filter_module.c中的48行,如YEBOYZQ

vim src/http/ngx_http_header_filter_module.c
static char ngx_http_server_string[] = "Server: nginx" CRLF;
static char ngx_http_server_string[] = "Server: nginx" YEBOYZQ;  //更改后的

前提是你执行了隐藏版本号,但如果你的版本号是开着的,我们还需要修改src/core/nginx.h中的13-14行,比如Server:YEBOYZQ/1.9.0

vim src/core/nginx.h
#define NGINX_VERSION "1.9.0"
#define NGINX_VER "nginx/" NGINX_VERSION
 
#define NGINX_VERSION "1.9.0"  //更改后的
#define NGINX_VER "YEBOYZQ/" NGINX_VERSIO  //更改后的

Server返回的就是常量NGINX_VER, 我们把NGINX_VERSION大小定义为1.9.0,nginx改成YEBOYZQ就可以了。

三、PHP

1、需要将php.ini中的expose_php = On,改为Off

vim /etc/php/php.ini
expose_php = Off

2、然后重启php-fpm或nginx或apache的服务,头信息中将隐藏X-Powered-By:PHP/5.6.0。

来源:https://www.yeboyzq.com/linux/ruanjiananzhuangweihu/1050.html

本文链接:https://jeff.xin/post/109.html

--EOF--

Comments

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。