我们都知道HTTP中有一个HEADER 头信息,通过 PHP 函数 HEADER 可以向客户端浏览器代理发送一个 HEADER 头。比如:

1
2
3
4
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */

header('Location: http://www.example.com/');

默认情况下 PHP 解释器会自动向客户端浏览器代理发送一个名为:X-Powered-By 的 HEADER ,如下图:

这样就暴露了服务器 PHP 的版本(当然 NGINX 也发送了他的版本)。如果是恶意的用户,发现服务器当前版本正好有漏洞并加以攻击的话,就会很麻烦。

以下是 NGINX 配置清除这些敏感的 HEADER 信息:
使用 NGINX 的 HEADERS_MORE 模块。
配置很简单,在 nginx.conf 的 HTTP 章节中加入:

1
    more_clear_headers 'X-Powered-*';

因为 MAC 的 PORTS 没有提供 HEADERS_MORE 模块的安装。这里提供一个 PATCH ,以及一个完整的 PORTFILE 文件,添加 HEADERS_MORE 模块。需要修改的文件是:/opt/local/var/macports/sources/rsync.macports.org/release/ports/www/nginx/Portfile。点击这里下载包


  • Portfile.nginx.headers_more 是完整的 Portfile 文件
  • Portfile.Nginx.Headers_more.patch 是补丁,使用命令 sudo patch -p0 < Portfile.Nginx.Headers_more.patch 即可

修改后,Variants 就多了一个 headers_more 选项,然后就可以安装拉。

1
2
3
4
5
6
Nroe# port info nginx
nginx @1.0.11 (www, mail)
Variants:             addition, dav, debug, flv, geoip, google_perftools, gzip_static, headers_more, [+]ipv6, mail, perl5, realip, redis, secure_download, ssl,
                      status, substitution, upload, zip

Nroe# sudo port -d install nginx +headers_more

PS:另外一种办法是让 PHP 解析器直接不输出 HEADER 信息。可以通过修改 PHP 源代码来实现,但考虑到 PHP 可能需要更新的维护问题,所以还是推荐在 WEB 服务器这层将 HEADER 信息清除掉。

Tagged with:
 

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Set your Twitter account name in your settings to use the TwitterBar Section.