亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

通過Nginx定義Header頭信息的實現步驟

瀏覽:66日期:2023-06-15 15:23:25

通過修改nginx的conf文件,輕松達到自定義HTTP Header的目的。

Nginx 使用 ngx_headers_more 模塊來增加、刪除出站、入站的 Header 信息。默認該模塊沒有加入到 Nginx 的源碼中,要想使用相關功能需要在編譯 Nginx 時加入該模塊。本人服務器中的 Nginx 在編譯時沒有加入該模塊,使用 -V 查看當前 Nginx 的編譯參數:

[root@z-dig ~]# nginx -V
nginx version: www.z-dig.com
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.z-dig.com 的 Header 信息:

[root@KVM ~]# curl -I www.z-dig.com
HTTP/1.1 200 OK
Server: www.z-dig.com
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.z-dig.com
HTTP/1.1 200 OK
Server: www.z-dig.com
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

[root@KVM ~]#

經測試已成功將請求返回中的 Header 指定信息刪除。想了解 ngx_headers_more 的其他功能請訪問項目官網。

到此這篇關于通過Nginx定義Header頭信息的實現步驟的文章就介紹到這了,更多相關Nginx定義Header頭信息內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: Nginx
主站蜘蛛池模板: 一级片毛片 | 亚洲成人第一页 | 爱爱小视频在线观看网站 | 激情婷婷色 | 欧美精品做人一级爱免费 | 97麻豆精品国产自产在线观看 | 欧美中文字幕一区二区三区 | 国产精品玖玖玖影院 | 成人免费福利网站在线看 | 国产欧美日韩一区二区三区 | 国产成人www免费人成看片 | 九九国产在线视频 | 日韩我不卡 | 亚洲成在人网站天堂一区二区 | 亚洲日韩中文字幕天堂不卡 | 亚洲一级黄色大片 | 成人免播放器午夜视频 | 精品国产一区二区三区四 | 在线不卡一区 | 青青青视频免费一区二区 | 老司机日日摸夜夜摸精品影院 | 成年女人毛片免费观看不卡 | 91香蕉福利一区二区三区 | 在线欧美v日韩v国产精品v | 美女大黄大色一级特级毛片 | 综合久久一区二区三区 | 国产亚洲精品第一区在线观看 | 黄色美国| 风间由美理伦片在线观看 | 做爰全过程免费的视69频 | 中国美女一级毛片 | 亚洲午夜大片 | 嫩草视频在线观看免费 | 日本一级特黄毛片高清视频 | 高清一级做a爱视频免费 | 国产精品原创永久在线观看 | 51精品视频免费国产专区 | 桃花阁成人网在线观看 | 日本特黄特色大片免费视频 | 国产一级二级三级在线观看 | 给我一个可以看片的www日本 |