## 응용 예제 ④ — proxy_cache (응답 캐싱)
## /etc/nginx/nginx.conf 의 http {} 블록 또는 conf.d 에 proxy_cache_path 필요

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=api_cache:10m
                 max_size=1g inactive=60m use_temp_path=off;

server {
    listen 80;
    server_name _;

    location /api/ {
        proxy_cache api_cache;
        proxy_cache_valid 200 5m;
        proxy_cache_valid 404 1m;
        proxy_cache_use_stale error timeout updating http_500 http_502;
        proxy_cache_lock on;
        add_header X-Cache-Status $upstream_cache_status;
        proxy_pass http://127.0.0.1:3000;
    }
    access_log /var/log/nginx/lab-cache.access.log;
}
