Welcome! Log In Create A New Profile

Advanced

Nginx: using X-Accel-Expires with Cache-Control

Posted by tereska 
Nginx: using X-Accel-Expires with Cache-Control
November 01, 2014 06:43PM
I'm using Nginx as a caching proxy server. I have problems with caching responses using both X-Accel-Expires and Cache-Control headers.

My upstream returns some request body with headers to nginx:
[...]
X-Accel-Expires: 60
Cache-Control: no-cache
[...]

My intent is that nginx will cache response for 60 seconds but clients will get only cache-control: no-cache header (so they will not cache response in the browser).

But nginx isnt caching that response. Nginx honour cache-control header and ignoring X-Accel-Expires header. I thought that X-Accel-Expires is "stronger" that Cache-Control but it is not.

Is there any way to change that?

I know that I can use:
proxy_ignore_headers Cache-Control;

But I cant do that because I don't have X-Accel-Expires headers in every response from upstream server.

To sum up when I return thoose headers from upstream:
X-Accel-Expires: 60
Cache-Control: no-cache
I want to cache response in nginx cache for 60s but return to clients cache-control: no-cache

But when I return this:
Cache-Control: max-age=90
(without X-Accel-Expires header) I want to cache response in nginx cache for 60s and return to clients Cache-Control: max-age=90 header.

Is this possible?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 107
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready