nginx 学习博客

王大爷 2020年08月27日 469次浏览
  • 如何配置缓存请求 并且区分出不需缓存的url
location ^~ /排除链接 {
      proxy_pass http://demo.net;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      client_max_body_size 10m;
    }
    location / {
      proxy_pass http://demo.net;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      client_max_body_size 10m;
      
      ## 设置请求缓存 配置
      proxy_cache tmp-test;
      proxy_cache_valid 200 304 1h;
      proxy_cache_valid any 10m;
      proxy_cache_key $host$uri$is_args$args;
      add_header Nginx-Cache "$upstream_cache_status";
      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    }

参考博客1