如果后端服务器关闭,我需要nginx代理使用缓存:
这是我的配置。但似乎是nginx使用不带检查后端服务器的缓存。
http {
  # ...
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_cache_path /tmp/nginx levels=1:2 keys_zone=tmpzone:10m inactive=60m;
  proxy_cache_key "$scheme$request_method$host$request_uri";
  server {
    server_name _;
    location / {
      proxy_connect_timeout 5s;
      proxy_read_timeout 5s;
      proxy_cache tmpzone;
      proxy_cache_valid      200 304 1d;
      proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host 'www.example.com';
      proxy_pass http://www.example.com;
    }
  }
}
问题是,如果后端服务器启动,如何绕过代理缓存?当后端服务器启动时,我的代理服务器根本不使用缓存。
                  到底是什么问题?
                
                
                  
                    —
                    珍妮D 
                    
                  
                
              
                  问题是,如果后端服务器启动,如何绕过代理缓存?
                
                
                  
                    —
                    sweb 
                    
                  
                
              
                  一个开箱即用的解决方案可能是运行2个“服务器”,其中一个具有缓存,一个不带缓存,并使用上游模块   nginx.org/en/docs/http/ngx_http_upstream_module.html?最好的解决方案可能是能够使用proxy_cache_bypass并检查后端是否存在...虽然我不知道如何使该工作正常...有趣的情况。
                
                
                  
                    —
                    SvennD