Add a purge endpoint and add more header controls
This commit is contained in:
25
nginx.conf
25
nginx.conf
@@ -11,11 +11,10 @@ http {
|
||||
|
||||
proxy_cache_path /etc/nginx/data/cache levels=1:2 keys_zone=api_cache:10m max_size=100g inactive=365d;
|
||||
|
||||
error_log /dev/stdout debug;
|
||||
error_log /dev/stdout warn;
|
||||
access_log /dev/stdout;
|
||||
|
||||
# Use Docker's internal DNS
|
||||
resolver 127.0.0.11 valid=10s;
|
||||
resolver 127.0.0.11 valid=60s;
|
||||
|
||||
server {
|
||||
listen 3000;
|
||||
@@ -31,8 +30,26 @@ http {
|
||||
proxy_ssl_server_name on;
|
||||
|
||||
proxy_cache api_cache;
|
||||
proxy_cache_valid 200 365d;
|
||||
|
||||
# Cache 2xx by default, or status codes from X-Status header
|
||||
proxy_cache_valid 200 201 202 203 204 206 365d;
|
||||
|
||||
# If X-Status header is present, cache those status codes instead
|
||||
set $cache_status $http_x_status;
|
||||
if ($cache_status != "") {
|
||||
proxy_cache_valid $cache_status 365d;
|
||||
}
|
||||
|
||||
# Bypass cache if X-NoCache header is present
|
||||
proxy_cache_bypass $http_x_nocache;
|
||||
proxy_no_cache $http_x_nocache;
|
||||
|
||||
add_header X-Cache-Status $upstream_cache_status always;
|
||||
}
|
||||
|
||||
# Cache purge endpoint
|
||||
location ~ /purge(/.*) {
|
||||
proxy_cache_purge api_cache $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user