Hi, i've come accross a strange problem of caching. My site is run by nginx 1.2.1, on two different servers. The config are exactly the same (i use puppet to mirror configs). The contents are exactly the same, everything that i can think of is exactly identical on both servers. In the config, i set "expires max" for the /static location. The two nginx are behind a haproxy instance for loadbalancing and failover. The setup is in active-active mode. When i load a page with no browser cache, each item in the static location is served by nginx with the correct response regarding the max-age and expire directives. Then i reload the page : some of these ressources are served with a 304 response (that is the expected behaviour), some with a 200 code (hence, a fresh copy of the file). If i reload the page again and again, the ressources served with 304 answer are varying. Now, i've put the server into active-backup mode, and only one instance of nginx is serving the files. In this setup, the ressources are always served with a 304 answer. Did i miss something? I assume that my servers setup is quite common, and i d'ont believe that the behaviour i observe is "normal". Any idea? thanks Florian Posted at Nginx Forum: http://forum.nginx.org/read.php?2,232235,232235#msg-232235
on 2012-10-25 22:35
on 2012-10-26 12:42
Hello! On Thu, Oct 25, 2012 at 04:34:14PM -0400, florian.iragne wrote: > The setup is in active-active mode. > with a 304 answer. > > Did i miss something? I assume that my servers setup is quite common, and i > d'ont believe that the behaviour i observe is "normal". > > Any idea? Symptoms suggest last modification times are different for the same static file on different servers. You have to sync files between servers with modification time preserved for conditional requests to work correctly ("rsync -a" is usually a good starting point). -- Maxim Dounin http://nginx.com/support.html
on 2012-10-26 13:57
Ok, now i understand. The browser sends a request withe the
if-not-modified-since corresponding to one server to the other server,
and
this one reply with 200 since the mtime is in the future of the
if-not-modified-since
is there any simple solution to handle this? I don't want to rsync
assets
between the servers
I use django in my project and its static/collectstatic process. So, i
force
the mtime of each static file collected, afet each collecstatic
operation. I
give the command line if someone fall in the same trap:
./manage.py collectstatic --noinput && find static -type f -exec touch
-t
$(date +%m%d%H)00 '{}' \;
Now, the cache is working as intended and my servers are in
active-active
setup.
Thanks for your answer that leads me to the solution
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,232235,232254#msg-232254
on 2012-10-27 14:36
Yesterday Oct 26, 2012 at 07:57 florian.iragne wrote: > Ok, now i understand. The browser sends a request withe the > if-not-modified-since corresponding to one server to the other server, and > this one reply with 200 since the mtime is in the future of the > if-not-modified-since > > is there any simple solution to handle this? I don't want to rsync assets > between the servers http://nginx.org/r/if_modified_since if_modified_since before; -- WNGS-RIPE
on 2012-10-29 09:00
Thanks for your answer. However, it's not secure enough for me and i prefer adding one more command line to the deployment process to ensure cache is working. thanks Posted at Nginx Forum: http://forum.nginx.org/read.php?2,232235,232297#msg-232297
on 2012-10-29 09:39
Hello! On Sat, Oct 27, 2012 at 03:35:51PM +0300, Oleksandr V. Typlyns'kyi wrote: > http://nginx.org/r/if_modified_since > if_modified_since before; 1) This will work only if you'll switch off ETag's as well. 2) This isn't a solution, but a bandaid. It won't fix the real problem (mtimes mismatch), but will make response with greatest mtime eventually win. Even with only 2 servers used this will still result in about 1.5x more 200 responses than needed. -- Maxim Dounin http://nginx.com/support.html
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.