每次使用Github的时候,尤其clone项目的时候github的速度总是非常感人,我有个香港的轻型服务器,而nginx可以反向代理,为什么我不使用nginx反向代理一个Github呢?

操作

  • 申请域名证书
  • 安装NGINX
  • 创建一个配置文件
upstream github {
    server github.com:443;
    keepalive 16;
}

server {
    listen 80;
    server_name github.guiyun.plus;
    rewrite ^ https://$http_host$request_uri? permanent;
}

server
{
    listen 443;
    server_name github.guiyun.plus;
    ssl_certificate   ssl/github.guiyun.plus.crt;
    ssl_certificate_key  ssl/github.guiyun.plus.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") #防止搜索引擎收录
    {
        return 403;
    }
    location / {
        proxy_set_header Accept-Encoding "";
        proxy_set_header Connection "";
        proxy_http_version 1.1;
        proxy_connect_timeout    10s;
        proxy_read_timeout       10s;
        proxy_set_header Host github.com;

        proxy_hide_header Strict-Transport-Security; #隐藏协议头,避免因为反向代理开启hsts

        proxy_pass https://github;
    }
}
  • 重启Nginx

这样Github就搭建好了

效果

访问了一下感觉速度还是可以的

搭建Github镜像站_github

而clone的服务就非常让人惊喜了

搭建Github镜像站_ide_02

唯一比较遗憾的就是没办法登录了,如果有什么登录的办法,还请小伙伴们告诉我