Welcome! Log In Create A New Profile

Advanced

Set Expires Header only if upstream has not already set an Expires

Posted by Thomas Glanzmann 
Thomas Glanzmann
Set Expires Header only if upstream has not already set an Expires
November 22, 2017 10:50AM
Hello,
I would like to add an Expires Header only to upstream content that has
not already set an Expires header. Is there an easy way to do that with
nginx?

I thought about trying to add a header_filter_by_lua checking the
Expires header and set the necessary value if not already set. Is there
an easier way to do the same?

Cheers,
Thomas
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
On Wed, Nov 22, 2017 at 10:41:49AM +0100, Thomas Glanzmann wrote:

Hi there,

> I would like to add an Expires Header only to upstream content that has
> not already set an Expires header. Is there an easy way to do that with
> nginx?

http://nginx.org/r/expires has an example of setting a value based on
$sent_http_content_type.

You can set a value based on $upstream_http_expires --

{ default off; "" 7d; }

in the appropriate "map" should set your Expires time to 7 days from now
if there is not an Expires: header from the upstream.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Hello francis,

> > Howto set expires only if upstream does not have set an expires?

> * Francis Daly <[email protected]> [2017-11-23 00:26]:

> You can set a value based on $upstream_http_expires --

> { default off; "" 7d; }

> in the appropriate "map" should set your Expires time to 7 days from
> now if there is not an Expires: header from the upstream.

thanks a lot. That solved my problem. I used the same:

map $upstream_http_expires $expires {
default off;
"" 7d;
}

server {
....
expires $expires;
}

Works like a charm. Thank you again for solving my problem. I thought about
using a map but missed the 'off' possibility and its behaviour.

Cheers,
Thomas
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login