Answer the question
In order to leave comments, you need to log in
nginx directory caching exception?
there is a subdomain for returning api (json or xml )
most of the data is static, given without authorization, and their obsolescence is not critical, therefore everything is cached using nginx tools,
but there are requests (directories) where data should be returned without cache (or with a minimum cache - 1m )
config:
proxy_cache_path /mnt/cache_nginx/json levels=1:2 keys_zone=cache_api:100m inactive=72h max_size=1G;
server {
listen 443 ssl;
location ~ (\.xml|\.json)$ {
proxy_cache cache_api;
proxy_cache_valid 502 503 1m;
proxy_cache_valid 404 1h;
proxy_cache_valid any 3d;
proxy_cache_key $request_uri;
proxy_intercept_errors off;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
# зона запросов, где кеш отключен
location /user/ {
proxy_cache off;
}
}
Answer the question
In order to leave comments, you need to log in
First, nginx checks the location with the prefix, then it finds the location with the regex since it is more specific. Accordingly, all directives will be applied from `location ~ (\.xml|\.json)$ {`.
The solution is to make /user/ more specific and put it at the beginning (order is important):
proxy_cache_path /mnt/cache_nginx/json levels=1:2 keys_zone=cache_api:100m inactive=72h max_size=1G;
server {
listen 443 ssl;
# зона запросов, где кеш отключен
location ~ /user/.*(\.xml|\.json)$ {
proxy_cache off;
proxy_intercept_errors off;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
location ~ (\.xml|\.json)$ {
proxy_cache cache_api;
proxy_cache_valid 502 503 1m;
proxy_cache_valid 404 1h;
proxy_cache_valid any 3d;
proxy_cache_key $request_uri;
proxy_intercept_errors off;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question