总结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 ;
       expires      3024010s;

       }

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

参与评论