Skip to content

Instantly share code, notes, and snippets.

@bungabear
Forked from sirsquidness/proxy.conf
Last active February 8, 2023 08:23
Show Gist options
  • Save bungabear/71571daf83a997178559abae809aec3e to your computer and use it in GitHub Desktop.
Save bungabear/71571daf83a997178559abae809aec3e to your computer and use it in GitHub Desktop.
Nginx Proxy with Cache for Github
events {
worker_connections 1024;
}
# cahce all through github.com
http {
# cache option inactive delete after 30days, total cache size 2G, cache index 1M (8,000)
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=cache_zone:1m inactive=30d max_size=2048m;
proxy_temp_path /var/cache/nginx/temp/;
sendfile on;
server {
listen 80;
client_max_body_size 300M;
location / {
proxy_cache cache_zone;
proxy_pass https://github.com;
proxy_cache_key $scheme$proxy_host$uri;
proxy_cache_valid 200 206 300h;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_intercept_errors on;
# handle redirect page in error_page
error_page 301 302 307 = @handle_redirects;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Expires;
proxy_hide_header Set-Cookie;
proxy_hide_header Cache-Control;
proxy_hide_header Expires;
}
# for redicrect page cache
location @handle_redirects {
set $original_uri $uri;
set $orig_loc $upstream_http_location;
proxy_pass $orig_loc;
proxy_cache cache_zone;
# But we store the result with the cache key of the original request URI
# so that future clients don't need to follow the redirect too
proxy_cache_key $original_uri;
proxy_cache_valid 200 206 300h;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
resolver 8.8.8.8; # Seems to be needed for redirects.
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Expires;
proxy_hide_header Set-Cookie;
proxy_hide_header Cache-Control;
proxy_hide_header Expires;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment