冰豆网

分享网络精彩
bingdou.com.cn

nginx反向代理github

时间:2025-03-06加入收藏

因为众所周知的缘故,github时常访问不了,于是就想着反代一下,刚好有台华为云的香港服务器,于是火毅盾的负责人就给了我以下代码
此反代除了登录其他基本没啥问题
1.打开宝塔面板,找到网站的反向代理,设置代理地址为https://github.com,发送域名为$host,然后确定之后可以看到有个配置文件,将如下代码放进去


#PROXY-START/

location ^~ /
{
    proxy_pass https://github.com;
    proxy_set_header Host github.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    proxy_set_header Accept-Encoding "";
        sub_filter "github.githubassets.com" "assets-github.bingdou.com.cn";
        sub_filter "github.com" "github.bingdou.com.cn";
        sub_filter "api.github.com" "api-github.bingdou.com.cn";
        sub_filter 'raw.githubusercontent.com' 'raw.github.bingdou.com.cn';
        sub_filter_once off;
        sub_filter_types *;

        # 处理 302 重定向中的地址替换
        proxy_redirect ~^https://raw.githubusercontent.com(.*)$ https://raw.github.bingdou.com.cn$1;
    # 隐藏后端服务器返回的 Content-Security-Policy 头部
        proxy_hide_header Content-Security-Policy;

        # 添加自定义的 Content-Security-Policy 头部
        add_header Content-Security-Policy "default-src 'self'; img-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'";
    
    
    set $static_fileHbPPNEua 0;
    if ( $uri ~* ".(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_fileHbPPNEua 1;
        expires 1m;
    }
    if ( $static_fileHbPPNEua = 0 )
    {
        add_header Cache-Control no-cache;
    }
}
#PROXY-END/

2.其中为bingdou.com.cn的后缀都需要更改为你的域名
3.在宝塔的网站里比如github.bingdou.com.cn中再添加其他例如api-github.bingdou.com.cn的域名
4.去服务商那解析这几个子域名即可

 
打 赏
打赏二维码

TGA: 技巧

分享到:


官方微信二维码冰豆网官方微信公众号