T
T
The Whiz2017-01-18 16:32:24
Nginx
The Whiz, 2017-01-18 16:32:24

How to set rules in nginx location for all folders except one and its subfolders?

I want to set cache-control on images from the server, except for those that are in the /forum folder and its subfolders. The global rule looks like this:

location ~* \.(?:jpg|jpeg|gif)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

To exclude the forum, I tried
~* ^/forum/.*\.(?:jpg|jpeg)$
But it did not give any effect. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2017-01-18
@modernstyle

Make /forum and / locations, in the second place the one about caching.

location /forum {
...
}

location / {
   location ~* \.(?:jpg|jpeg|gif)$ {
...
   }
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question