欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 运维知识 > nginx >内容正文

nginx

nginx添加ngx-凯发k8官方网

发布时间:2024/1/23 nginx 111 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 nginx添加ngx_http_headers_module模块 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

    今天由于公司微信端添加地图业务,但地图不支持https,所以将https改为http访问,因此出现访问异常,原因是之前访问的用户,微信端存在缓存页面,但是不会清楚,所以我就提出,可以在nginx在主机头跳转的时候做清楚缓存的操作,让微信端访问时,响应头不存储缓存,这样就解决问题了,下面是配置的过程(配置很简单,但是这个过程我花了1天的时间,如果有坑,请留言)

官方文档:http://nginx.org/en/docs/http/ngx_http_headers_module.html

1.查看档期啊nginx版本及确认安装目录

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

版本及目前使用的模块信息

[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.下载headers模块

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

3.记录下当前访问页面的状态(也可以在web页面上查看 响应头信息)

[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.将header模块,编译到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

(如果现在已经部署了nginx 就不能make install ,如果没有部署nginx 可以make install)

5.替换nginx启动文件 (yo)

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

6.重启服务,测试是否正常

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

7.验证效果

[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.添加到nginx 指定站点配置文件中

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.重新加载

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

##web页面查看结果##

 

 

总结

以上是凯发k8官方网为你收集整理的nginx添加ngx_http_headers_module模块的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图