Skip to content

Instantly share code, notes, and snippets.

@lalizita
Created June 23, 2022 20:47
Show Gist options
  • Save lalizita/c047d706dfb833fdc46399ba09674e28 to your computer and use it in GitHub Desktop.
Save lalizita/c047d706dfb833fdc46399ba09674e28 to your computer and use it in GitHub Desktop.
Cache config for NGINX
events{
worker_connections 1024;
}
http {
# A shared memory zone to keep cache
proxy_cache_path /etc/nginx/cache keys_zone=mycache:10m;
server {
listen 8080;
location / {
# Our origin server domain, it will return a data response
proxy_pass http://server:8082;
# What cache will be used, the key_zone in proxy_cache_path
proxy_cache mycache;
# header that show cache status
add_header X-Cache-Status $upstream_cache_status;
# when proxy is valid
proxy_cache_valid 200 10s;
# set a key to cache
proxy_cache_key $host$uri$is_args$args;
# use cache when the origin server return some of these errors
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
# bypass to not use cache
proxy_cache_bypass $arg_nocache;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment