Skip to content

Instantly share code, notes, and snippets.

@crosstyan
Last active September 24, 2020 16:15
Show Gist options
  • Select an option

  • Save crosstyan/c13bbd2500f91084c97704e4ccac04d3 to your computer and use it in GitHub Desktop.

Select an option

Save crosstyan/c13bbd2500f91084c97704e4ccac04d3 to your computer and use it in GitHub Desktop.
A nginx.conf for reverse proxy gist
http {
# 缓存位置配置
# 必须要放到http区块, 否则会报错
# 不用缓存的话可以把它删了
proxy_cache_path /var/cache/nginx/ levels=1:2 keys_zone=gist_cache:10m max_size=1g inactive=60m use_temp_path=off;
# Server区块开始
server {
listen 80;
#换成你自己的域名
server_name gist.example.com;
# 你的SSL设定
# 配置文件略, 别直接抄
location / {
#反代地址
proxy_pass https://gist.github.com/;
# 我猜是代理有效时间
proxy_cache_valid 200 302 1h;
proxy_cache_valid 404 1m;
#当Gist挂掉的时候使用本机缓存 (虽然我觉得可能是本机先挂掉)
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_set_header User-Agent $http_user_agent;
# sub_filter 这几项是用来替换你原本网站的gist的
# (似乎不能过滤JavaScript中的请求?)
# 丢到你网站的Server区可以避免你手工一个个换域名的麻烦
sub_filter https://gist.github.com/ https://gist.example.com/;
sub_filter https://gist.github.com/ https://gist.example.com/;
sub_filter_once off;
#上面配置的 proxy_cache_path 的 keys_zone
proxy_cache gist_cache;
# 其他缓存设置, 我也不知道有啥用
proxy_cache_revalidate on;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment