Question

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?

Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top