Skip to content

Instantly share code, notes, and snippets.

@satrobit
Created June 3, 2019 14:40
Show Gist options
  • Save satrobit/526c91635f2ae603c98eabebbc0be880 to your computer and use it in GitHub Desktop.
Save satrobit/526c91635f2ae603c98eabebbc0be880 to your computer and use it in GitHub Desktop.
NGINX Cache Cluster
error_log logs/error.log;
events {
worker_connections 512;
}
worker_processes 4;
http {
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=default_cache:10m max_size=2g inactive=120m use_temp_path=off;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 302 60m;
upstream cache {
hash $scheme$proxy_host$request_uri consistent;
server <CACHE-SERVER-1>:8080;
server <CACHE-SERVER-2>:8080;
server <CACHE-SERVER-3>:8080;
}
upstream origin {
hash $scheme$proxy_host$request_uri consistent;
server <BACKEND-SERVER-1>:80;
server <BACKEND-SERVER-2>:80;
server <BACKEND-SERVER-3>:80;
server <BACKEND-SERVER-4>:80;
}
server {
listen 80;
location / {
proxy_buffering on;
proxy_pass http://cache;
}
}
server {
listen 8080;
location / {
proxy_cache default_cache;
proxy_buffering on;
proxy_ignore_headers Expires;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_hide_header X-Accel-Expires;
proxy_hide_header Expires;
proxy_hide_header Cache-Control;
proxy_hide_header Pragma;
proxy_set_header Host <HOSTNAME>;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_pass http://origin;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment