1

I have an nginx setup with multiple server blocks. I'd like to know if there's a way to globally set the value of expires to max for all images, CSS and JS across the server.

I know I can use this:

location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
   expires max;
}

But then I'd have to add it to every server block, since location isn't allowed in http.

Is there a way to set expires to max for specific mime-types or extensions, globally?

  • 1
    you can add it in a separate config file, and import it in all ur servers – Mohammad AbuShady Jun 22 '13 at 17:08
  • @MohammadAbuShady that would be the awesome workaround (thanks!) :) I'll use that unless/until a neater syntax is possible. Could you write an example for this workaround? –  Jun 22 '13 at 17:20

1 Answers1

1

Try it first cause I haven't tested this before.

conf file /etc/nginx/img-cache.conf for example

location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires max;
}

server

server {
    #bla bla
    include /etc/nginx/img-cache.conf;
    #bla bla
}
Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89