Caching proxy server on NGINX

February 12, 2023

Caching proxy server on NGINX

Example: Caching jpg, jpeg, png, CSS, and js files for 60 minutes.

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_cache:20m inactive=60m;

add_header Cache-Control "public, max-age=3600";

location ~* \\.(jpg|jpeg|png|css|js)$ {
    proxy_cache static_cache;
    proxy_cache_valid 200 60m;
    proxy_pass http://localhost;
}