Remember the fiasco at the end of 2014 and the beginning of 2015, when Emacs Wiki was down as I tried to switch to Fast CGI, and it kept staying down as I tried to use mod_perl, when finally Nic Ferrier stepped in and started paying for new hosting. He used nginx as a caching proxy for Apache, which continued to call the wiki as a simply CGI script.
as I tried to switch to Fast CGI
The comments reveal quite a bit of caching issues, though. The problem was that nginx seemed to ignore that two pages with an identical URL but for different language preferences could be different. This in turn meant that a German visitor to a page not in the cache would put the page in the cache but with German menus at the bottom, for example (”Diese Seite bearbeiten” instead of “Edit this page”). And if the next visitor to the same page didn’t understand German, this was annoying.
I thought the answer was that Apache should send the “Vary” header telling the cache that `accept-language` should be part of the cache key. See this discussion of the Vary header, for example: Understanding the HTTP Vary Header and Caching Proxies. But it just didn’t work.
Understanding the HTTP Vary Header and Caching Proxies
Recently, I suddenly realized that perhaps nginx doesn’t care about the Vary header Apache is sending. I learned about the `proxy_header_key` setting in the nginx caching guide. As you can see, the default is inadequate! `$scheme$proxy_host$request_uri` is not what I’m expecting. I needed to add http_accept_language to that key:
1. proxy cache key is $scheme$proxy_host$request_uri by default proxy_cache_key $scheme$proxy_host$request_uri$http_accept_language;
I get the feeling that things are working, right now! If so, it only took 17½ month to find the solution. I’m writing it down in case anybody else stumbles over this problem (and in case I need to remember in the future).
Perhaps the problem is also related to how I compute Etags for my pages: the wiki doesn’t take `accept-language` into account when computing Etags. Now that I think about it, perhaps that would also have helped solve the problem?
#Emacs #Wikis #Web #nginx