---
# System prepended metadata

title: caddy制作github与docker反向代理

---

# caddy制作github与docker反向代理

挂壁哥的朋友都是傻屌，上不去GitHub。挂壁哥只好做了反代。为什么不用cloud flare的worker？因为封号啊。废话少说。
## 准备：
- 一个域名，由cf管理
- 海外服务器vps

## cloudflare操作
开到DNS界面，新增三条映射到vps的ip
![image](https://hackmd.io/_uploads/rkRMu7R8xl.png)

- 一条是`github`
- 一条是`*.github`
- 一条是`*.docker`


等五分钟，喝杯白开水先
## 修改/etc/caddy/Caddyfile
在下面新增
github部分
```
github.你的域名 {
    reverse_proxy https://github.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://github.com
        header_down Location (https://github.com)(.*) https://github.你的域名$2
    }
}

gist.github.你的域名 {
    reverse_proxy https://gist.github.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://gist.github.com
        header_down Location (https://gist.github.com)(.*) https://gist.github.你的域名$2
    }
}

raw.github.你的域名 {
    reverse_proxy https://raw.githubusercontent.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://raw.githubusercontent.com
        header_down Location (https://raw.githubusercontent.com)(.*) https://raw.github.你的域名$2
    }
}

api.github.你的域名 {
    reverse_proxy https://api.github.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://api.github.com
        header_down Location (https://api.github.com)(.*) https://api.github.你的域名$2
    }
}

codeload.github.你的域名 {
    reverse_proxy https://codeload.github.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://codeload.github.com
        header_down Location (https://codeload.github.com)(.*) https://codeload.github.你的域名$2
    }
}

avatars.github.你的域名 {
    reverse_proxy https://avatars.githubusercontent.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://avatars.githubusercontent.com
        header_down Location (https://avatars.githubusercontent.com)(.*) https://avatars.github.你的域名$2
    }
}

user-images.github.你的域名 {
    reverse_proxy https://user-images.githubusercontent.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://user-images.githubusercontent.com
        header_down Location (https://user-images.githubusercontent.com)(.*) https://user-images.github.你的域名$2
    }
}



```
docker部分
```
hub.docker.你的域名 {
    reverse_proxy https://hub.docker.com {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
        header_up Origin https://hub.docker.com
        header_down Location (https://hub.docker.com)(.*) https://hub.docker.你的域名$2
    }
}

registry.docker.你的域名 {
    reverse_proxy https://registry-1.docker.io {
        header_up Host registry-1.docker.io
        header_up X-Forwarded-Host {host}
        header_up Origin https://registry-1.docker.io
        header_down Location (https://registry-1.docker.io)(.*) https://registry.docker.你的域名$2
    }
}

```
最后重启caddy
```
 sudo systemctl restart caddy
```
### docker配置修改
修改`/etc/docker/daemon.json`
```
{
  "registry-mirrors": ["https://registry.docker.你的域名"]
}
```
重启docker
`sudo systemctl restart docker
`


完全免费社工库
下山虎社工库
https://t.me/MTTigerSGK
#社工库 #免费社工库