我尝试使用nginx的proxy_cachefunction来提供索引页面。 一切工作正常与普通的浏览器。 但是当我尝试使用curl获取页面的内容,或者当我在索引页面上使用围攻时,nginx开始不按我的预期工作。 当页面caching过期时,它将请求传递给apache。
我无法理解,为什么nginx在curl或siege请求时不会创build索引页面的新caching?
这里是nginx.conf的一部分:
proxy_cache_path /var/cache/nginx levels=2 keys_zone=pagecache:100m inactive=1m max_size=500m; location = / { set $o_uri $request_uri; if ( $http_cookie !~ "mytestcookie" ) { rewrite ^ /ng_cache last; } proxy_pass http://127.0.0.1:88; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /ng_cache { internal; root /home/$host/www; proxy_cache pagecache; proxy_cache_valid 200 301 302 304 1m; proxy_hide_header "Set-Cookie"; proxy_ignore_headers "Cache-Control" "Expires"; proxy_pass http://127.0.0.1:88$o_uri; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
configuration中的proxy_hide_header Set-Cookie行build议您的后端返回Set-Cookie头,这会阻止nginx 默认caching这样的响应。 您可能想在您的configuration中将Set-Cookie添加到proxy_ignore_headers :
proxy_ignore_headers Cache-Control Expires Set-Cookie;
详情请参阅文档 。