隐藏Apache
Apache在所有文档请求和服务器生成的文档(例如500内部服务器错误文档)中都会输出一个服务器签名。有两个配置指令负责控制此签名:ServerSignature和ServerTokens。
1. Apache的ServerSignature指令 ServerSignature指令负责插入与Apache的服务器版本、服务器名(通过ServerName指令设置)、端口和编译模块有关的一行输出。启用这个指令时,如果与ServerTokens
Apache/2.0.59(Unix) DAV/2 PHP/6.0.0-dev Server at www.example.com Port 80
很明显,这样的信息是你想自己保留的项。因此,可以考虑将这个指令设置为指令(下面将会介绍)一起使用,就能够显示类似于下面的输出:Off来禁用。
尽管ServerSignature禁用时该指令是没有意义的,但ServerSignature由于某种原因必须被启用时,可以考虑将该指令设置为Prod。
隐藏PHP
还可以把你在使用PHP来驱动网站的这一事实隐藏起来,或者至少不那么明显。使用expose_php指令就能避免将PHP版本信息追加到Web服务器签名的最后。不允许访问phpinfo() 可以防止攻击者得到你的软件版本号和其他重要信息。通过改变文档扩展名,使得这些页面映射到PHP脚本不容易被看出来。
1.expose_php = On | Off 作用域:PHP_INI_SYSTEM;默认值:On。
启用时,PHP指令expose_php将细节追加到服务器签名后面。例如,如果启用了ServerSignature,ServerTokens设置为Full,并且启用了此指令,服务器签名的有关部分如下:
Apache/2.0.44(Unix) DAV/2 PHP/5.0.0b3-dev Server at www.example.com Port 80
如果expose_php被禁用,则服务器签名如下所示:
Apache/2.0.44(Unix) DAV/2 Server at www.example.com Port 80
For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it prevents the accidental injection of trailing whitespace into the response.
在PHP的官方资料中才也有提到这个:
The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.