Skip to content

Instantly share code, notes, and snippets.

@Rubix982
Created June 18, 2023 10:40
Show Gist options
  • Save Rubix982/8335e412fe332a692a469904976e9c82 to your computer and use it in GitHub Desktop.
Save Rubix982/8335e412fe332a692a469904976e9c82 to your computer and use it in GitHub Desktop.
Caching Algorithms, NGINX, with help from the NGINX Community, Medium, GPT, OReilly
# Base
server {
list 8080:
server_name localhost;
location / {
proxdy_pass $BACKEND_URL;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
proxy_cache_revalidate on;
proxy_cache_valid 200 302 10m;
add_header X-Cache-Status $upstream_cache_status;
}
}
### Least Time
# proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m inactive=60m use_temp_path=off;
# proxy_cache_key "$scheme$request_method$host$request_uri";
# proxy_cache_valid 200 1h;
# proxy_cache_valid 404 1m;
# proxy_cache_min_uses 1;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
### Least Connections
# proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m inactive=60m use_temp_path=off;
# proxy_cache_key "$scheme$request_method$host$request_uri";
# proxy_cache_valid 200 1h;
# proxy_cache_valid 404 1m;
# proxy_cache_min_uses 1;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_lock on;
# proxy_cache_lock_timeout 5s;
# proxy_cache_lock_age 5s;
### LRU ###
# proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m inactive=60m use_temp_path=off;
# proxy_cache_key "$scheme$request_method$host$request_uri";
# proxy_cache_valid 200 1h;
# proxy_cache_valid 404 1m;
# proxy_cache_min_uses 1;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_revalidate on;
# proxy_cache_background_update on;
### LFU ###
# proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m inactive=60m use_temp_path=off;
# proxy_cache_key "$scheme$request_method$host$request_uri";
# proxy_cache_valid 200 1h;
# proxy_cache_valid 404 1m;
# proxy_cache_min_uses 1;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_revalidate on;
# proxy_cache_background_update on;
# proxy_cache_lock on;
# proxy_cache_lock_timeout 5s;
# proxy_cache_lock_age 5s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment