0

My default NGinx installation is returning a 304 Not Modified response to a request which has a matching If-None-Match header and a non-expired If-Modified-Since header which is correct behaviour but NGinx also adds the content of the resource to the 304 response. One would think that NGinx wouldn't add the content, but simply return the 304 with an empty body indicating to the browser that using their cached resource is sufficient.

Is there a reason for this behaviour and how do I disable it?

  • The way this is worded is confusing. Exactly what behavior are you seeing? – Michael Hampton Jul 28 '16 at 18:15
  • @MichaelHampton Is this more clear? – sethmlarson Jul 28 '16 at 18:20
  • OK, that makes sense. But how do you know it's nginx doing it? It might be your web application. – Michael Hampton Jul 28 '16 at 18:31
  • @MichaelHampton It's serving static unchanging files, nothing dynamic! – sethmlarson Jul 28 '16 at 18:34
  • How do you check that nginx sends file body? – Alexey Ten Jul 29 '16 at 10:18
3

Are you sure NGINX is returning the content?

Depending on how you're viewing the response, this might only appear to be the case.

For example, when Chrome dev tools receives a 304 from NGINX, it displays the content, which looks like it was sent from NGINX, but in reality is just being retrieved from cache by Chrome.

You can try this out by right clicking the file -> "Copy -> Copy as cURL" in the Chrome dev tools.

Add -vv to the beginning of what you just copied (ex curl -vv <your-url> -H 'HeaderKey: HeaderValue' <etc>), then execute in terminal/shell.

You'll probably see that it doesn't return body content (even though it is a 304.) You can then try the same request with just the URL (curl -vv <your-url>), and see a body without the 304.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.