0

I'm trying to add etag based cache verification to a web app I've developed that runs on Apache via an NGINX reverse proxy. The web app is written in Perl. In the Perl script, I check for the $ENV{'HTTP_IF_NONE_MATCH'} header and then test the etag in it, if it exists. If I access the app via cURL, it works:

timothybutler@timothys-MacBook-Pro ~ % curl -I https://server/resource/podcast/20211101.mp3
HTTP/1.1 200 OK
Server: nginx/1.21.4
Date: Fri, 12 Nov 2021 18:06:37 GMT
Content-Type: audio/mpeg
Content-Length: 16665729
Connection: keep-alive
Surrogate-Control: no-cache
Cache-Control: private,max-age=864000
Etag: "1635825322"

Giving that etag back via cURL, I get the expected result:

timothybutler@timothys-MacBook-Pro ~ % curl -H 'If-None-Match: "1635825322"' -I https://server/resource/podcast/20211101.mp3
HTTP/1.1 304 Not Modified
Server: nginx/1.21.4
Date: Fri, 12 Nov 2021 18:19:29 GMT
Connection: keep-alive
Cache-Control: private, max-age=864000
Etag: "1635825322"

However, the process breaks down if I try it in Chrome instead. Chrome reports sending If-None-Match: "1635825322" as one of the headers when I refresh the page, but my server does not set the HTTP_IF_NONE_MATCH environmental variable for that request contrary to the one that came in via cURL. If I dump all of the %ENV hash, the If-Match-None header and its etag is simply not present in any form when Chrome issues the request.

Timothy R. Butler
  • 703
  • 2
  • 11
  • 22
  • 1
    Use tcpdump to find out who dumps it, Nginx or Apache. Did you tell Nginx to pass it through? Oh, and why do you put a reverse proxy in front of a reverse proxy? – Gerard H. Pille Nov 13 '21 at 02:59
  • @GerardH.Pille I don't really have any experience with tcpdump -- is there a good recommendation you could give me re: flags for watching this? As to NGINX, it is serving the static content for the site, while I'm using Apache to spawn FastCGI processes for Perl. I've run into some issues trying to get FastCGI to spawn properly directly under NGINX. – Timothy R. Butler Nov 14 '21 at 04:37
  • In which case you should have let Apache deal with the static content too - but I'm quite sure Nginx could have handled all you need. Have a look at the examples in tcpdump's manual page. IIRC, I'd run a "tcpdump -A -s0" on the port on which Apache is listening, to see if the "if-none-match" is still there. But: "Did you tell Nginx to pass it through?" – Gerard H. Pille Nov 14 '21 at 05:46

0 Answers0