proxy_cache_path /var/cache/nginx
keys_zone=cache_test:10m
levels=1:2
inactive=2M
max_size=10g
use_temp_path=off;
proxy_cache_key $scheme$proxy_host$request_uri;
proxy_cache_methods GET;
log_format cache '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" cs=$upstream_cache_status';
server {
listen 3001;
access_log /var/log/nginx/cache_test-proxy.access.log cache;
error_log /var/log/nginx/cache_test-cache.error.log;
set $backend http://127.0.0.1:3000;
location / {
proxy_pass $backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /products {
proxy_pass $backend;
proxy_cache_bypass $http_pragma;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
proxy_cache cache_test;
proxy_cache_valid 200 304 30s;
}
}