Nginx add ngx_http_headers_module module

    Today, because the company added a map service on the WeChat side, but the map does not support https, so https was changed to http access, so the access exception occurred. The reason is that the user who visited before has a cached page on the WeChat side, but it is not clear, so I proposed , You can do a clear cache operation when nginx jumps in the host header, and when the WeChat side accesses it, the response header does not store the cache. This solves the problem. The following is the configuration process (the configuration is very simple, but this process takes me 1 day, if there is a pit, please leave a message)

Official document: http://nginx.org/en/docs/http/ngx_http_headers_module.html

1. Check the schedule ah nginx version and confirm the installation directory

cd /home/oldboy/tools/
wget -q http://nginx.org/download/nginx-1.8.1.tar.gz
tar xf nginx-1.8.1.tar.gz
cd nginx-1.8.1

Version and current module information

[root@web01 extra]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --with-http_stub_status_module --with-http_ssl_module --prefix=/application/nginx-1.8.1/
###注意一定要事先查看当前nginx下有哪些编译模块,记录,然后与要添加的模块一起编译

2. Download the headers module

cd /home/qiuyuetao/
wget https://codeload.github.com/openresty/headers-more-nginx-module/zip/master\
unzip headers-more-nginx-module-master.zip

3. Record the status of the currently visited page (you can also view the response header information on the web page)

[root@web01 qiuyuetao]# curl -I www.etiantian.org
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.9
Date: Wed, 02 Aug 2017 06:17:47 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: 
###这里可以修改内容很多,只是用到里面的一点点知识,其它内容,大家可以科普##

4. Compile the header module into nginx

cd /home/qiuyuetao/tools/nginx-1.8.1    ##这个下载的安装文件目录
./configure --with-http_stub_status_module  --with-http_ssl_module --prefix=/application/nginx-1.8.1/ --add-module=/home/qiuyuetao/headers-more-nginx-module-master
###注意一定要事先查看当前nginx下有哪些编译模块,记录,然后与要添加的模块一起编译##
make

(If you have deployed nginx now, you can’t make install, if you don’t deploy nginx, you can make install)

5. Replace nginx startup file (yo)

cd  /application/nginx/sbin
mv nginx{,.bak}
cp nginx /application/nginx/sbin/
##这个是将重新编译的nginx 配置文件,复制到安装目录使新的模块生效

6. Restart the service and test whether it is normal

/application/nginx/sbin/nginx -s stop
/application/nginx/sbin/nginx
/application/nginx/sbin/nginx -V

7. Verify the effect

[root@web01 qiuyuetao]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --with-http_stub_status_module --with-http_ssl_module --prefix=/application/nginx-1.8.1/ --add-module=/home/qiuyuetao/headers-more-nginx-module-master

8. Add to nginx designated site configuration file

server{
        listen  80;
        server_name www.etiantian.org;
        location / { ##将下面header信息写入location下  ## max-age设定缓存时间 nocashe 就是不缓存
add_header  Cache-Control no-cache;
add_header  Cache-Control no-store;
add_header  Pragma no-cache;
add_header  Expires 0;
}

9. Reload

 /application/nginx/sbin/nginx -s stop
 /application/nginx/sbin/nginx

##web页看结果##

wKioL1mBlOmBnn5MAAAVRrLhyb8347.png

 

 

Guess you like

Origin blog.csdn.net/zhangge3663/article/details/108072754