欢迎来到代码驿站!

Nginx

当前位置:首页 > 服务器 > Nginx

总结Nginx 的使用过程中遇到的问题及解决方案

时间:2022-10-23 11:17:02|栏目:Nginx|点击:

在启动 Nginx 的时候,有时候会遇到这样的一个错误:

复制代码 代码如下:

[emerg]: could not build the proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64

 解决办法就是在配置文件中新增以下配置项:

复制代码 代码如下:

proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;

 这两个配置项的 size 根据系统后端发送的 header 来进行设置。

注:默认值的话,就会上面出现上面那样出现错误
 
Nginx 缓存刷新问题

在使用 Nginx 的过程中,因为 Nginx 本地使用了缓存,然后发布了静态资源后, CDN 回源的时候,发现没有正常回源,经过查询发现,是因为 Nginx 本地有缓存,而有没有对缓存进行刷新的原因,要刷新本地缓存,可以安装 Purge 模块。

Nginx 的缓存设置:

复制代码 代码如下:

location /
      {
       proxy_cache cache_go;
       proxy_cache_valid 200 304 1d;
       proxy_cache_key $host$uri$is_args$args;
       proxy_set_header Host  $host;
       proxy_set_header X-Forwarded-For  $remote_addr;
       proxy_pass http://127.0.0.1:8800;
       expires      3024010s;

       }

       location ~ /purge(/.*)
       {
        #设置只允许指定的IP或IP段才可以清除URL缓存。
        allow            127.0.0.1;
        deny             all;
        proxy_cache_purge    cache_go   $host$1$is_args$args;
       }

 Purge 模块是用来清除缓存的,首先下载安装 Puerge 模块。

下载 Purge 模块:
wget http://labs.frickle.com/files/ngx_cache_purge-1.2.tar.gz

 解压:
tar -zxvf ngx_cache_purge-1.2.tar.gz

 再编译前先使用如下命令查看 nginx 的编译选项:

复制代码 代码如下:

/home/nginx/sbin/nginx -V
nginx version: xxxx
TLS SNI support enabled
configure arguments: --prefix=/home/nginx-1.2.8 --with-pcre=../pcre-8.31 --with-zlib=../zlib-1.2.3 --with-openssl=../openssl-1.0.0d --with-http_ssl_module --with-http_stub_status_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=../ngx_cache_purge-1.5 --add-module=../perusio-nginx-http-concat-321e344 --add-module=../ngx_http_vipshop_hostname_filter --with-ld-opt=-static

 上面我的编译显示有 puerge 模块,是因为我已经编译过了,然后在原有的编译参数后面加上:

复制代码 代码如下:

--add-module=/home/ngx_cache_purge-1.5

 退出 Nginx ,并重新启动:

复制代码 代码如下:

./nginx -s quit
./nginx

 配置 Puerge :

复制代码 代码如下:

location ~ /purge(/.*)
       {
        #设置只允许指定的IP或IP段才可以清除URL缓存。
        allow            127.0.0.1;
        deny             all;
        proxy_cache_purge    cache_go   $host$1$is_args$args;
       }

 清楚 Nginx 缓存的方式,比如你的 url 是 http://test.com/test/test.js
 那清除该 js 缓存的命令即为:

复制代码 代码如下:

 通用的方式就是:

复制代码 代码如下:

 其中 uri 就是你的 URL “http://test.com/test/test.js” 的 “test/test.js” 部分。

上一篇:Apache Hudi结合Flink的亿级数据入湖实践解析

栏    目:Nginx

下一篇:没有了

本文标题:总结Nginx 的使用过程中遇到的问题及解决方案

本文地址:http://www.codeinn.net/misctech/217116.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有