11

Switching from apache to nginx, and encountering something weird.

1) Say I have a file yo.txt in the document root of my site and it contains 'foo'.

curl http://localhost/yo.txt => 'foo'

2) then I alter the file to contain 'bar'

curl http://localhost/yo.txt => 'foo' (still!)

If I remove yo.txt, I get a 404. If I remove all the text, I correctly get an empty file when I curl the url.

I checked the last modified HTTP header after I modify the file, and it is correct, even though the contents of the file are stale.

I'm using the standard configuration from nginx after an apt-get install nginx.

what gives?

Josh Nankin
  • 2,518
  • 4
  • 28
  • 45
  • Possible duplicate of [Vagrant/VirtualBox/Apache2 Strange Cache Behaviour](http://stackoverflow.com/questions/9479117/vagrant-virtualbox-apache2-strange-cache-behaviour) – kenorb Dec 13 '16 at 14:04

2 Answers2

15

I'm using Vagrant. Setting sendfile to off in nginx.conf fixed the problem as found here, e.g."

sendfile off;
Community
  • 1
  • 1
Josh Nankin
  • 2,518
  • 4
  • 28
  • 45
  • This should be marked as the correct answer - so glad I found this, was experiencing a VERY strange behavior with static files until disabling `sendfile`. – Scott Byers Jun 15 '17 at 17:38
  • 7
    I like magical solutions, but anybody knows why and how this fixes the problem? – ichigolas Feb 02 '18 at 17:47
  • This is a [work around for a known problem with old versions of VirtualBox](https://stackoverflow.com/questions/9479117/vagrant-virtualbox-apache2-strange-cache-behaviour). – Raedwald Sep 23 '19 at 16:27
0

For me the following worked:

    expires modified 10y;

According to the docs:

The time in the “Expires” field is computed as a sum of the current time and time specified in the directive. If the modified parameter is used (0.7.0, 0.6.32) then the time is computed as a sum of the file’s modification time and the time specified in the directive.

infografnet
  • 3,749
  • 1
  • 35
  • 35
  • Well, nice answer. But pretty useless as long as it is not clear where (which file, where in file) to put `expires modified 10y;` – toom Jan 30 '22 at 13:20