想在国内VPS上连接Github,但是网络苦不堪言,只有20kb/s。
想要加速访问,有正代和反代两个途径。本文说反代,用sniproxy实现的。
sniproxy项目地址:https://github.com/dlundquist/sniproxy
一、安装sniproxy
Debian/Ubuntu
- apt-get install -y git autotools-dev cdbs debhelper dh-autoreconf dpkg-dev gettext libev-dev libpcre3-dev libudns-dev pkg-config fakeroot devscripts
- git clone https://github.com/dlundquist/sniproxy.git
- cd sniproxy
- ./autogen.sh && dpkg-buildpackage
- dpkg -i ../sniproxy_*_*.deb
- apt-get install -y sniproxy
Redhat/CentOS
- yum install -y git autoconf automake curl gettext-devel libev-devel pcre-devel perl pkgconfig rpm-build udns-devel
- git clone https://github.com/dlundquist/sniproxy.git
- cd sniproxy
- ./autogen.sh && ./configure && make dist
- rpmbuild --define "_sourcedir `pwd`" -ba redhat/sniproxy.spec
- yum install ../sniproxy-*.*.rpm
- yum install -y sniproxy
二、修改sniproxy配置
打开/etc/sniproxy.conf
找到开头就是table https_hosts {
这一行
添加两行,分别是 (.*.|)github.com$ *
和(.*.|)githubusercontent.com$ *
修改好后是下面这个样子
- # named tables are defined with the table directive
- table https_hosts {
- # When proxying to local sockets you should use different tables since the
- # local socket server most likely will not autodetect which protocol is
- # being used
- example.org unix:/var/run/server.sock
- (.*.|)github.com$ *
- (.*.|)githubusercontent.com$ *
- }
三、启动sniproxy
- sniproxy -c /etc/sniproxy.conf
关闭:pkill sniproxy
四、在客户端设置hosts
这里说的客户端也就是我开头说的国内VPS
修改/etc/hosts
如果原本有github的hosts配置了,就删除或者注释掉
添加下面的这些,把1.1.1.1
改为你启动了sniproxy的VPS的IP
- 1.1.1.1 gist.github.com
- 1.1.1.1 github.com
- 1.1.1.1 api.github.com
- 1.1.1.1 www.github.com
- 1.1.1.1 avatars0.githubusercontent.com
- 1.1.1.1 avatars1.githubusercontent.com
- 1.1.1.1 avatars2.githubusercontent.com
- 1.1.1.1 avatars3.githubusercontent.com
- 1.1.1.1 avatars4.githubusercontent.com
- 1.1.1.1 avatars5.githubusercontent.com
- 1.1.1.1 avatars6.githubusercontent.com
- 1.1.1.1 avatars7.githubusercontent.com
- 1.1.1.1 avatars8.githubusercontent.com
- 1.1.1.1 camo.githubusercontent.com
- 1.1.1.1 cloud.githubusercontent.com
- 1.1.1.1 gist.githubusercontent.com
- 1.1.1.1 marketplace-screenshots.githubusercontent.com
- 1.1.1.1 raw.githubusercontent.com
- 1.1.1.1 repository-images.githubusercontent.com
- 1.1.1.1 user-images.githubusercontent.com
其他
我没有更细致研究sniproxy的配置了,我想看看能不能在配置里只让指定的IP可以访问,不过在GitHub看了一下Issues,好像没看到方法,你们可以研究一下。
嗷嗷目前是用iptables来管理443端口指定IP放行
就这些,完成了。