博客原文
0031400 blog - nginx代理github下载和git clone
旧版 (2个域名)
server {
listen [::]:80;
server_name gh.domain.com;
location / {
proxy_pass https://github.com/;
proxy_set_header Host github.com;
proxy_redirect https://codeload.github.com/ https://gh.domain.com/codeload/;
sub_filter 'https://codeload.github.com/' 'https://gh.domain.com/codeload/';
proxy_redirect https://objects.githubusercontent.com/ https://gh.domain.com/objects/;
sub_filter 'https://objects.githubusercontent.com/' 'https://gh.domain.com/objects/';
}
location /codeload/ {
proxy_pass https://codeload.github.com/;
proxy_set_header Host codeload.github.com;
}
location /objects/ {
proxy_pass https://objects.githubusercontent.com/;
proxy_set_header Host objects.githubusercontent.com;
}
}
server {
listen [::]:80;
server_name raw.gh.domain.com;
location / {
proxy_pass https://raw.githubusercontent.com/;
proxy_set_header Host raw.githubusercontent.com;
}
}
需要gh.domain.com
和raw.gh.domain.com
指向你的机器
新版 (1个域名 支持gist 和 git clone)
nginx配置文件
server {
listen [::]:80;
server_name gh.yourdomain.com;
location = / {
return 404;
}
location /codeload/ {
proxy_pass https://codeload.github.com/;
proxy_set_header Host codeload.github.com;
}
location /objects-githubusercontent/ {
proxy_pass https://objects.githubusercontent.com/;
proxy_set_header Host objects.githubusercontent.com;
}
location /raw-githubusercontent/ {
proxy_pass https://raw.githubusercontent.com/;
proxy_set_header Host raw.githubusercontent.com;
}
location /gist/ {
proxy_pass https://gist.github.com/;
proxy_set_header Host gist.github.com;
proxy_redirect https://gist.githubusercontent.com/ https://gh.yourdomain.com/gist-githubusercontent/;
proxy_redirect https://codeload.github.com/ https://gh.yourdomain.com/codeload/;
}
location /gist-githubusercontent/ {
proxy_pass https://gist.githubusercontent.com/;
proxy_set_header Host gist.githubusercontent.com;
}
location / {
proxy_pass https://github.com/;
proxy_set_header Host github.com;
proxy_redirect https://codeload.github.com/ https://gh.yourdomain.com/codeload/;
proxy_redirect https://objects.githubusercontent.com/ https://gh.yourdomain.com/objects-githubusercontent/;
proxy_redirect https://raw.githubusercontent.com/ https://gh.yourdomain.com/raw-githubusercontent/;
}
}
使用方法
- 项目分支源码
https://github.com/gohugoio/hugo/archive/refs/heads/master.zip
https://gh.yourdomain.com/gohugoio/hugo/archive/refs/heads/master.zip
- 项目具体raw文件
https://github.com/gohugoio/hugo/raw/refs/heads/master/README.md
https://gh.yourdomain.com/gohugoio/hugo/raw/refs/heads/master/README.md
- release文件
https://github.com/gohugoio/hugo/releases/download/v0.145.0/hugo_0.145.0_linux-amd64.tar.gz
https://gh.yourdomain.com/gohugoio/hugo/releases/download/v0.145.0/hugo_0.145.0_linux-amd64.tar.gz
- release代码
https://github.com/gohugoio/hugo/archive/refs/tags/v0.145.0.tar.gz
https://gh.yourdomain.com/gohugoio/hugo/archive/refs/tags/v0.145.0.tar.gz
- git clone https
git clone https://github.com/gohugoio/hugo.git
git clone https://gh.yourdomain.com/gohugoio/hugo.git
- gist raw
https://gist.github.com/imba-tjd/d73258f0817255dbe77d64d40d985e76/raw/b7e9b1c0f86205ab4ebaab0ed652aa06e999075a/.Cloud.md
https://gh.yourdomain.com/gist/imba-tjd/d73258f0817255dbe77d64d40d985e76/raw/b7e9b1c0f86205ab4ebaab0ed652aa06e999075a/.Cloud.md
- gist打包
https://gist.github.com/imba-tjd/d73258f0817255dbe77d64d40d985e76/archive/b7e9b1c0f86205ab4ebaab0ed652aa06e999075a.zip
https://gh.yourdomain.com/gist/imba-tjd/d73258f0817255dbe77d64d40d985e76/archive/b7e9b1c0f86205ab4ebaab0ed652aa06e999075a.zip