从响应标头中删除服务器:Apache

时间:2014-09-12 09:22:01

标签: php apache ubuntu http-headers

我想知道如何完全删除apache在响应中发送的服务器头。

最初,它在响应标头中显示了完整的服务器信息,如Server: Apache (Ubuntu 14.04)。 但我在某处读到了在apache2.conf中添加它的内容

ServerTokens ProductOnly

ServerSignature Off

它没有删除标题,只是将其更改为Server: Apache

我甚至尝试从PHP中移除header_remove('Server');的标头。但仍然没有运气。

所以,我想完全删除它。

谢谢,

PS:如果可以更改标题值,例如:Server: Microsoft-IIS/8.0(假值);那也没关系。

4 个答案:

答案 0 :(得分:2)

服务器ID /令牌标头由" ServerTokens"指令(由mod_core提供)。除了修改Apache HTTPD源代码或使用mod_security模块之外,没有其他方法可以完全抑制服务器ID标头。

使用mod_security方法,您可以禁用modsecurity.conf文件中的所有模块指令/功能,并且只使用服务器标头ID指令而不需要任何额外的行李。" (c)Chipster

答案 1 :(得分:2)

2020更新:

要在使用mod_security模块时使用@Maxym建立以上答案,请注意-不能完全删除该模块的服务器头(只能通过源代码编辑/重新编译),但是您可以重命名公共服务器签名-通过此说“ NinjaServer” mod_security模块!

要这样做;

我们必须(在httpd.conf或同等版本中)保持/设置;

ServerTokens Full

然后通过mod_security2.conf;

SecServerSignature "NinjaServer"

另外,最好最后加载mod_security模块,以避免在Apache错误日志中发出通知。

对于OpenSuse 15.x / Apache 2.4.x安装程序,实际步骤是;

 zypper -v in apache2-mod_security2 // install mod_security
 a2enmod security2                  // enable the module
 a2enmod unique_id                  // this was needed too...
 a2enmod -l                         // verify loaded

接下来,编辑httpd.conf.local(在/ etc / apache2下)并设置;

 ServerTokens Full

接下来,编辑mod_security2.conf(在/ etc / apache2下)并设置;

 SecRuleEngine DetectionOnly         // only remove apache server name
 SecServerSignature "NinjaServer"    // some name other than Apache

也将其注释掉(此示例仅用于修改Public Server Signature);

# Include /usr/share/apache2-mod_security2/rules/modsecurity_crs_10_setup.conf

然后通过

重新启动apache
systemctl restart apache2

如果您现在要检查标题,您将看到 服务器名称显示为NinjaServer:-)

答案 2 :(得分:2)

This 是我发现的最好方法:

sudo apt-get install libapache2-mod-security2

然后将其添加到 /etc/apache2/apache.conf(您可以使用任何名称,这里我使用了空格):

<IfModule security2_module>
    SecRuleEngine on
    ServerTokens Min
    SecServerSignature " "
</IfModule> 

并重启Apache:

sudo service apache2 restart

现在当你运行类似:

curl -v http://localhost:80/ | head

你应该得到:

< HTTP/1.1 200 OK
< Date: Mon, 25 Jan 2021 09:31:11 GMT
* Server  is not blacklisted
< Server:

有关详细信息,请参阅 here

答案 3 :(得分:0)

在 Raspberry Pi 操作系统上测试:Raspbian Buster(发布日期:2021 年 3 月 4 日) 内核版本:5.10)

Apache 版本:2.4.38

安装 mod-security

sudo apt-get install libapache2-mod-security2 -y

修改security.conf

sudo nano /etc/apache2/conf-available/security.conf

如下

ServerTokens Prod

复制模板

sudo cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf

修改 modsecurity.conf

sudo nano /etc/modsecurity/modsecurity.conf

如下

SecRuleEngine DetectionOnly
SecServerSignature "Noop"

重启服务器

sudo service apache2 restart

来源

相关问题