1

I have a weird issue where enabling proxy_caching in nginx disables 304 responses from nginx for the same requests. The server return HTTP 200 responses. My configuration file

daemon off; pid nginx.pid; events {} http { log_format serve-time '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$request_time" "$http_if_modified_since"'; server { listen 9791 default_server; access_log nginx-access-log.log serve-time; error_log nginx-error-log.log; location ~/insync { return 200; } location ~ / { expires 1d; add_header Cache-Control public; # add the cache status for the response as a header add_header X-Cache-Status $upstream_cache_status; proxy_set_header Host $remote_addr; proxy_set_header If-Modified-Since $http_if_modified_since; proxy_pass http://backend; # use the cache configured above proxy_cache MY_CACHE; # cache only 200 Ok requests for 365 days proxy_cache_valid 200 365d; } } upstream backend { server localhost:9792; } proxy_cache_path nginx-cache/ levels=1:2 keys_zone=MY_CACHE:100m max_size=90g inactive=365d; } 

When cache is enabled, the server returns 200 OK responses. When I comment out proxy_cache_valid statement (which disables cache), the server returns HTTP 304 for same requests. I am issuing requests as follows

curl -i -H "If-Modified-Since: Thu, 28 May 2020 21:43:48 GMT" "http://localhost:9791/hello" 

Anyone know what I am doing wrong here?

1 Answer 1

1

I figured out the issue. It seems that nginx by-default looks for an exact match between the last modified and if-modified-since header. Setting this property in the config to 'before' value fixed the issue

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.