Opened 9 years ago
Last modified 9 years ago
#964 accepted defect
Expires header incorrectly prioritised over Cache-Control: max-age
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | nginx-core | Version: | 1.9.x |
Keywords: | Cc: | ||
uname -a: | Linux cbranch-vm 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux | ||
nginx -V: |
nginx version: nginx/1.9.7
built by gcc 4.9.2 (Debian 4.9.2-10) |
Description
When using nginx as a caching reverse proxy, items may be cached for the wrong amount of time if the Expires header is inconsistent with max-age. Caching will be disabled if the Expires header value is in the past or malformed.
Per RFC 2616 section 14.9.3, max-age takes precedence over Expires. However, nginx prefers whichever header/directive occurs first in the response, which causes unexpected results when migrating to nginx from an RFC-compilant caching reverse proxy.
A minimally-reproducible config is attached. Observe that no file is cached when accessing http://127.0.0.2:8080/fail, but a file is cached when accessing http://127.0.0.2:8080/success.
Attachments (1)
Change History (2)
by , 9 years ago
Attachment: | nginx.conf added |
---|
comment:1 by , 9 years ago
Component: | documentation → nginx-core |
---|---|
Status: | new → accepted |
The description isn't really correct: nginx prefers
Cache-Control
overExpires
. But ifExpires
is given first and disables caching, nginx won't cache the response. This is believed to be correct, though may be suboptimal in some cases.See 6a3ab6fdd70f for some additional details on the current behaviour. Previous attempts to address things can be found in this thread.