nginx not serving updated static files

2019-04-21 15:30发布

问题:

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?

回答1:

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

sendfile off;


回答2:

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.



标签: nginx