vps交流

nginx反向代理缓存 html 策略跳过cookies的配置改进


请问各位懂nginx的,location ~ .*.(html)?$ {这个配置这样写正确吗,有什么改进和错误的语句吗

  1. location ~ .*.(html)?$ {
  2.     proxy_ignore_headers X-Accel-Expires Cache-Control Expires Set-Cookie Vary;
  3.     proxy_hide_header Cache-Control;
  4.     proxy_hide_header Set-Cookie;
  5.     proxy_hide_header Vary;
  6.     proxy_set_header Accept-Encoding "";
  7.     proxy_set_header X-Real-IP $remote_addr;
  8.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  9.     proxy_set_header Host $host;
  10.     proxy_set_header REMOTE_ADDR $remote_addr;
  11.     proxy_redirect off;
  12.     proxy_pass https://101.102.104.5;
  13.     proxy_cache blo**n;
  14.     proxy_cache_lock on;
  15.     proxy_cache_lock_age 5s;
  16.     proxy_cache_lock_timeout 5s;
  17.     proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  18.     proxy_cache_background_update on;
  19.     proxy_cache_min_uses 1;
  20.     proxy_cache_valid 200 304 1d;
  21.     proxy_cache_valid 500 502 503 504 0s;
  22.     proxy_cache_valid any 10s;
  23.     proxy_cache_revalidate on;
  24.     proxy_cache_methods GET HEAD POST;
  25.     add_header Cache-Control max-age=5;
  26.     proxy_cache_key $uri$is_args$args;
  27.     add_header CDN-Cache "$upstream_cache_status";
  28.     #设置Cookie不缓存
  29.     set $do_not_cache 0;
  30.     if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
  31.       #set $do_not_cache 1;
  32.      }
  33.     #跳过缓存
  34.     proxy_cache_bypass $do_not_cache;
  35.     #不保存缓存
  36.     proxy_no_cache $do_not_cache;
  37.     }

复制代码

还行