Summarize the problems and solutions encountered in the use of Nginx

  • 2020-05-09 19:52:08
  • OfStack

When you start Nginx, you sometimes get an error like this:


[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

 's solution is to add the following configuration items to the configuration file:


proxy_headers_hash_max_size 51200 ;
proxy_headers_hash_bucket_size 6400 ;

The size of the two configuration items,  , is set according to the header sent by the back end of the system.

Note: default values will have the same error as above
 
Nginx cache refresh problem

In the process of using Nginx, because Nginx used the cache locally, and then published the static resources, when CDN returned to the source, it was found that there was no normal back source. After searching, it was found that Nginx had a local cache, but there was no reason to refresh the cache. To refresh the local cache, you can install the Purge module.

Cache Settings for 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(/.*)
       {
        # Setting allows only the specified IP or IP Segment can be cleared URL The cache.
        allow            127.0.0.1;
        deny             all;
        proxy_cache_purge    cache_go   $host$1$is_args$args;
       }

The   Purge module is used to clear the cache. First download and install the Puerge module.

Download Purge module:
wget http://labs.frickle.com/files/ngx_cache_purge-1.2.tar.gz

  extract:
tar -zxvf ngx_cache_purge-1.2.tar.gz

See the build options for nginx using the following command before compiling  :


/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

Above  , my compiler shows the puerge module, because I have already compiled it, and then I add:


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

  exits Nginx and restarts:


./nginx -s quit
./nginx

  configuration Puerge:


location ~ /purge(/.*)
       {
        # Setting allows only the specified IP or IP Segment can be cleared URL The cache.
        allow            127.0.0.1;
        deny             all;
        proxy_cache_purge    cache_go   $host$1$is_args$args;
       }

  Nginx cache way clearly, such as your url http: / / test com/test/test js
 's command to clear the js cache is:


curl http://test.com/purge/test/test.js

The general approach of   is:


curl http://test.com/purge/uri

  which uri is your URL http: / / test com/test/test js "" test/test. js" part.


Related articles: