Set `expires` by MIME type

Francis Daly francis at
Tue Sep 4 12:20:00 UTC 2018

On Mon, Sep 03, 2018 at 04:13:51PM -0400, petecooper wrote:

Hi there,

> I am attempting to use `expires` on Nginx 1.15.3 to define the expiry of
> files on a per MIME type basis.

It seems to work for me:

"xml" should have 0s, so now.
"rss" should have 1h.
"png" should have 1M.

$ curl -s -i | grep '^Content-Type\|^Expires'
Content-Type: text/xml
Expires: Tue, 04 Sep 2018 12:16:40 GMT

$ curl -s -i | grep '^Content-Type\|^Expires'
Content-Type: application/rss+xml
Expires: Tue, 04 Sep 2018 13:16:41 GMT

$ curl -s -i | grep '^Content-Type\|^Expires'
Content-Type: image/png
Expires: Thu, 04 Oct 2018 12:16:42 GMT

> In the browser inspector, all MIME types are assigned a 1 month expiry, as
> if they're inheriting the `default` value from the map. Example headers for
> a .php file:
>     Date: Mon, 03 Sep 2018 20:09:30 GMT
>     Expires: Wed, 03 Oct 2018 20:09:30 GMT

Can you do a test like the above, and show the Content-Type that is
received as well?

"A .php file" could be anything.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list