每次從github上拉東西,速度都奇慢無比,本地的時(shí)候可以設(shè)置代理,但是一些特殊場合并不是特別方便,所以就寫了下面的反向代理。
建議直接看這個(gè)
- https://ghostcir.com/s/169.html,通過一個(gè)域名加速各種網(wǎng)站
設(shè)置upstream(上游),ip地址可以通過dig github.com獲取,或者比較懶的,直接server github.com:443,它會(huì)自動(dòng)解析。
upstream github {
server 192.30.253.112:443;
server 192.30.253.113:443;
keepalive 16;#設(shè)置連接池加快訪問速度。
}
Nginx
配置https,也可以直接使用http,將listen 443 ssl http2 reuseport;替換成listen 80;就可以。
server
{
listen 443 ssl http2 reuseport;
ssl_certificate ssl/p.ghostcir.com.pem;
ssl_certificate_key ssl/p.ghostcir.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 1d;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets on;
ssl_stapling on;
server_name p.ghostcir.com; #綁定的域名
nginx
屏蔽搜索引擎
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;
}
nginx
配置反向代理
location / {
proxy_set_header Accept-Encoding ""; #不使用壓縮,如gzip
proxy_set_header Connection "";
proxy_http_version 1.1; #使用http1.1長連接
proxy_connect_timeout 10s; #設(shè)置連接超時(shí)
proxy_read_timeout 10s; #設(shè)置讀取超時(shí)
proxy_set_header Host github.com;
proxy_hide_header Strict-Transport-Security; #隱藏協(xié)議頭,避免因?yàn)榉聪虼黹_啟hsts
proxy_pass https://github;
}
}
nginx
最后貼一下完整規(guī)則
upstream github {
server 192.30.253.112:443;
server 192.30.253.113:443;
}
server
{
listen 443 ssl http2 reuseport;
ssl_certificate ssl/p.ghostcir.com.pem;
ssl_certificate_key ssl/p.ghostcir.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 1d;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets on;
ssl_stapling on;
server_name p.ghostcir.com; #綁定的域名
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; #隱藏協(xié)議頭,避免因?yàn)榉聪虼黹_啟hsts
proxy_pass https://github;
}
}