Nginx 使用 ngx_headers_more 模块来增加、删除出站、入站的 Header 信息。
ngx_headers_more 项目主页
默认该模块没有加入到 Nginx 的源码中,要想使用相关功能需要在编译 Nginx 时加入该模块。
本人服务器中的 Nginx 在编译时没有加入该模块,使用 -V 查看当前 Nginx 的编译参数:
[root@z-dig ~]# nginx -V
nginx version: www.111com.net
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www
--with-http_ssl_module --with-http_stub_status_module
[root@z-dig ~]#
从官网下载模块:
[root@z-dig ~]# cd /usr/local/src/
[root@z-dig src]# wget 、https://codeload.github.com/openresty/headers-more-nginx-module/zip/master
-O ./headers-more-nginx-module-master.zip
[root@z-dig src]# unzip headers-more-nginx-module-master.zip
重新编译 Nginx 前,请求 www.111com.net 的 Header 信息:
[root@KVM ~]# curl -I www.111com.net
HTTP/1.1 200 OK
Server: www.111com.net
Date: Sat, 23 Apr 2016 11:25:15 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.17
Vary: Accept-Encoding, Cookie
Cache-Control: max-age=3, must-revalidate
WP-Super-Cache: Served supercache file from PHP
[root@KVM ~]#
现在重新编译 Nginx ,平滑更新:
[root@z-dig ~]# cd /usr/local/src/nginx
[root@z-dig nginx]# make clean
rm -rf Makefile objs
[root@z-dig nginx]#./configure --prefix=/usr/local/nginx --user=www --group=www
--with-http_ssl_module --with-http_stub_status_module
--add-module=/usr/local/src/headers-more-nginx-module-master
[root@z-dig nginx]# make
[root@z-dig nginx]# make install
[root@z-dig nginx]# kill -s USR2 `cat /usr/local/nginx/logs/nginx.pid`
[root@z-dig nginx]# ps -ef|grep nginx
root 2017 1 0 Apr21 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 2018 2017 0 Apr21 ? 00:00:30 nginx: worker process
root 21717 2017 0 19:41 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 21718 21717 0 19:41 ? 00:00:00 nginx: worker process
root 21856 18312 0 19:45 pts/2 00:00:00 grep nginx
[root@z-dig nginx]# kill -s WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@z-dig nginx]# ps -ef|grep nginx
root 2017 1 0 Apr21 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root 21717 2017 0 19:41 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 21718 21717 0 19:41 ? 00:00:00 nginx: worker process
root 21943 18312 0 19:49 pts/2 00:00:00 grep nginx
[root@z-dig nginx]# kill -s QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@z-dig nginx]# ps -ef|grep nginx
root 21717 1 0 19:41 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 21718 21717 0 19:41 ? 00:00:00 nginx: worker process
root 22050 18312 0 19:54 pts/2 00:00:00 grep nginx
[root@z-dig nginx]#
到此 Nginx 已重新编译并平滑升级成功。
在 Nginx 的配置文件中加入代码,将之前请求网站返回 Header 中的 X-Powered-By 和 WP-Super-Cache 删除:
more_clear_headers 'X-Powered-By';
more_clear_headers 'WP-Super-Cache';
[root@z-dig ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@z-dig ~]# nginx -s reload
再次请求查看效果:
[root@KVM ~]# curl -I www.111com.net
HTTP/1.1 200 OK
Server: www.111com.net
Date: Sat, 23 Apr 2016 12:03:04 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding, Cookie
Cache-Control: max-age=3, must-revalidate
经测试已成功将请求返回中的 Header 指定信息删除。想了解 ngx_headers_more 的其他功能请访问项目官网。
凡尔赛法环免广告版 最新版v1.69.1
下载天煞异种 安卓版v1.0.21
下载十三月 (Undecember)最新官方中文版v3.26.0200
下载我不是废柴无限99999钻999999金币游戏 不减反增版v1.2.16
下载我的女友是声优免广告 安卓版v1
我的女友是声优免广告是一款非常好玩的模拟经营类手游,玩家在游
石器帝国去广告版 v8
石器帝国免广告版是游戏的破解版本,在该版本中为玩家去除了广告
校园恋爱模拟器真人版去广告版 v0.0.7
校园恋爱模拟器真人版免广告版是游戏的破解版本,在该版本中为玩
教练我要开球馆内置菜单修改器 安卓版v1.5.4
教练我要开球馆内购版是一款模拟经营类游戏,玩家们将在游戏中创
我的游轮无限砖石 安卓版v1.7.0
我的游轮无限金币钻石版是一款模拟经营类游戏,你将成为一艘游轮