色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

通過Nginx定義Header頭信息的實現(xiàn)步驟

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

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

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

[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 ~]#

從官網(wǎng)下載模塊:

[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 ~]#

現(xiàn)在重新編譯 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 的配置文件中加入代碼,將之前請求網(wǎng)站返回 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 ~]#

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

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

標(biāo)簽: Nginx
主站蜘蛛池模板: 欧美性性性性性色大片免费的 | 综合久久一区二区三区 | 九九精品成人免费国产片 | 亚洲综合性| 久久久精品国产 | 一级毛片在线 | 99re国产视频 | 国产a级一级久久毛片 | 欧美三区在线观看 | 天干夜天天夜天干天ww | 男人的天堂中文字幕 | 亚洲另类视频 | 亚洲成a人片在线网站 | xp123欧美亚洲国产日韩 | 全国男人的天堂网站 | 亚洲综合色一区二区三区另类 | 色综合久久久 | 亚洲第99页 | 狠狠做久久深爱婷婷97动漫 | 欧美成人一区二区 | 精品久久一区二区三区 | 中国二级毛片 | 香蕉521av网站永久地址 | 亚洲国产在 | 1024手机基地在线看手机 | 欧美一线高本道高清在线 | 97精品久久久久中文字幕 | 国产美女午夜精品福利视频 | 国产精品久久国产三级国不卡顿 | 亚洲国产精品免费观看 | 成年女人免费又黄又爽视频 | 欧美成人伊人十综合色 | 亚洲人在线播放 | 久久精品a一国产成人免费网站 | 国产午夜亚洲精品理论片不卡 | 美国一级片免费看 | 欧美一级黄 | 欧美成人综合在线 | 欧美日韩精品一区二区视频在线观看 | 日本高清一本二本三本如色坊 | 99久久99久久精品免费看子伦 |