nginx 緩存動態內容 和使用自定義錯誤503

安裝時添加 ngx_cache_purge 模塊 html

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=ngx_cache_purge-2.1 nginx

vi nginx.conf shell

proxy_temp_path   /home/nginx/temp;
proxy_cache_path  /home/nginx/cache  levels=1:2  keys_zone=cache_one:2000m inactive=24h max_size=80g;

vi proxy.conf 緩存


proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header;
proxy_connect_timeout 300s;
proxy_send_timeout   900;
proxy_read_timeout   900;
proxy_buffer_size    32k;
proxy_buffers     4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect     off;
proxy_hide_header  Vary;
proxy_set_header   Accept-Encoding '';
proxy_set_header   Host   $host;
proxy_set_header   Referer $http_referer;
proxy_set_header   Cookie $http_cookie;
proxy_set_header   X-Real-IP  $remote_addr;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_intercept_errors on;
proxy_redirect default;
proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie" "Vary";
其中



proxy_intercept_errors on;
proxy_redirect default;


用於503錯誤時使用自定義頁面 cookie


vi vhost/domain.conf dom


upstream test_server {
        server 192.168.130.54 max_fails=3 fail_timeout=5s;
        server 192.168.130.57 max_fails=3 fail_timeout=5s;
        server 192.168.130.51  backup;
}
server {
    listen  80;
    server_name test.pc6.com;
    location /test/ {
        proxy_cache cache_one;
        proxy_cache_valid  200 304 1d;
        proxy_ignore_headers cache-control;
        proxy_cache_key $host$uri$is_args$args;
        include proxy.conf;
        proxy_pass http://test_server;
        expires      1d;
        access_log  /home/wwwlogs/test.log log;
    }
    location ~ /jfclear(/.*) {
        #allow        127.0.0.1;
        allow        all;
        deny         all;
        proxy_cache_purge    cache_one  $host$1$is_args$args;
    }
    error_page 503 /50x.html;
    location = /50x.html {
        root   /home/html;
    }

 }
其中
proxy_ignore_headers cache-control;
用於強制緩存動態頁面
相關文章
相關標籤/搜索