<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 2, 2013 at 12:16 AM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello!<br>
<div><div class="h5"><br>
On Fri, Nov 01, 2013 at 10:29:06PM +0100, Marc Aymerich wrote:<br>
<br>
> Hi,<br>
> I'm using nginx proxy pass to cache content of our dynamic web application.<br>
><br>
> In order to save some bandwidth our client application uses conditional<br>
> requests based on ETag. However nginx ignores the ETag of cached pages :(<br>
><br>
> What would be required if I want to honor the ETag of cached pages? Is<br>
> something that can be achieve by means of configuration? or I would need to<br>
> write an nginx module in C?<br>
<br>
</div></div>It is expected to just work in 1.3.3+. If you don't see it<br>
working, you may want to check the version you are running.</blockquote><div><br></div><div>Hi maxim,</div><div>yeap I'm running 1.4.1 but I never get a 304 :( </div><div>This is what a response from cache looks like</div>
<div><br></div><div># wget --no-check https://[fdf5:5351:1dfd:0:0:0:0:2]/api/ -S --header 'If-None-Match: "83393a3900e4abce27212d7a27cae589"' -q</div><div> HTTP/1.1 200 OK</div><div> Server: nginx/1.4.1</div>
<div> Date: Sat, 02 Nov 2013 01:40:24 GMT</div><div> Content-Type: application/json</div><div> Transfer-Encoding: chunked</div><div> Connection: keep-alive</div><div> ETag: "83393a3900e4abce27212d7a27cae589"<br>
</div><div> Allow: GET, HEAD, OPTIONS</div><div> Vary: Accept, Cookie, Accept-Encoding</div><div> Expires: Sat, 02 Nov 2013 01:41:24 GMT</div><div> Cache-Control: max-age=60</div><div> </div></div><div>This is my nginx config for this cached location</div>
<div><br></div><div><div>location /api/ {</div><div> proxy_pass <a href="http://127.0.0.1:8080">http://127.0.0.1:8080</a>;</div><div> proxy_redirect off;</div><div> </div><div> proxy_ignore_headers Set-Cookie; </div>
<div> proxy_set_header Host $host;</div><div> proxy_set_header X-Real-IP $remote_addr;</div><div> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</div><div> proxy_set_header X-Forwarded-Protocol $scheme;</div>
<div> </div><div> proxy_cache cache;</div><div> proxy_cache_key $host$uri$is_args$args$http_accept_encoding$http_accept;</div><div> proxy_cache_valid 1m;</div><div> expires 1m;</div>
<div> </div><div> set $skip_cache 0;</div><div> if ($request_method != GET) {</div><div> set $skip_cache 1;</div><div> }</div><div> if ($http_cookie) {</div><div> set $skip_cache 1;</div><div>
}</div>
<div> if ($http_authorization) {</div><div> set $skip_cache 1;</div><div> }</div><div> proxy_cache_bypass $skip_cache;</div><div>}</div></div><div><br></div><div><br></div><div>Maybe is there some conflicting configuration? I can not see it :( and ETags work just fine if I request to my backend server</div>
<div><br></div><div><div># wget --no-check <a href="http://127.0.0.1:8080/api/">http://127.0.0.1:8080/api/</a> -S --header 'If-None-Match: "77e348fb6260a8dd90ca18c61f7cd472"' -q</div><div> HTTP/1.1 304 NOT MODIFIED</div>
<div> Server: nginx/1.4.1</div><div> Date: Sat, 02 Nov 2013 01:47:30 GMT</div><div> Content-Length: 0</div><div> Connection: keep-alive</div></div><div><br></div><div>Notice the etag value from cached content is different from the fresh one, even though the content is exactly the same, I presume this is nginx doing its job of updating the ETag for some differences because of caching, but still fails to reply a conditional request properly :(</div>
<div><br></div><div>Thanks for your help!!</div>-- <br>Marc
</div></div>