在啟動 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
新聞熱點
疑難解答