Skip to content

Instantly share code, notes, and snippets.

@shilman

shilman/sidebar Secret

Last active August 13, 2016 06:37
Show Gist options
  • Save shilman/0eec40cf2fb2c3c3694a209dd5691299 to your computer and use it in GitHub Desktop.
Save shilman/0eec40cf2fb2c3c3694a209dd5691299 to your computer and use it in GitHub Desktop.
proxy_cache_path /var/cache/nginx/sidebar levels=1:2 keys_zone=SIDEBAR:10m inactive=24h max_size=1g;
upstream sidebar {
ip_hash;
server xxx.xxx.xx.xxx:80;
server yyy.yyy.yy.yyy:80;
}
server {
listen 0.0.0.0:80;
server_name sidebar.io;
access_log /var/log/nginx/sidebar.access;
set $skip_cache 0;
location / {
# PROXY STARTS HERE ========
proxy_pass http://sidebar/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
# CACHING STARTS HERE ========
if ($cookie_meteor_login_token) {
set $skip_cache 1;
}
proxy_cache_bypass $skip_cache;
proxy_no_cache $skip_cache;
proxy_cache SIDEBAR;
proxy_cache_valid 200 30s;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_ignore_headers "Cache-Control" "Expires";
add_header X-Cached $upstream_cache_status;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment