NginxÂ ä½¿ç¨ ngx_headers_more 模åæ¥å¢å ãå é¤åºç«ãå ¥ç«ç Header ä¿¡æ¯ã
ngx_headers_more 项ç®ä¸»é¡µ
é»è®¤è¯¥æ¨¡å没æå å ¥å° Nginx çæºç ä¸ï¼è¦æ³ä½¿ç¨ç¸å ³åè½éè¦å¨ç¼è¯ Nginx æ¶å å ¥è¯¥æ¨¡åã
æ¬äººæå¡å¨ä¸ç Nginx å¨ç¼è¯æ¶æ²¡æå å ¥è¯¥æ¨¡å,ä½¿ç¨ -V æ¥çå½å Nginx çç¼è¯åæ°:
Â
1 2 3 4 5 6 7 8 | [ 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 ~ ] # |
ä»å®ç½ä¸è½½æ¨¡å:
Â
1 2 3 4 | [ 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 ä¿¡æ¯:
Â
1 2 3 4 5 6 7 8 9 10 11 12 | [ 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 ,å¹³æ»æ´æ°:
Â
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [ 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 å é¤:
Â
1 2 | more_clear _headers 'X-Powered-By' ; more_clear _headers 'WP-Super-Cache' ; |
Â
Â
1 2 3 4 | [ 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 |
å次请æ±æ¥çææ:
Â
1 2 3 4 5 6 7 8 9 10 | [ 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 ~ ] # |