最近 switch 上有了狂野飙车,但是在酒店的网络死活连不上。刚好朋友的 switch 想用舞力全开 unlimited 也不行,就天天试着各种方法。
开始就想着花钱用各种加速器,但是出差只带了公司的电脑,各种限制,电脑上开了各种加速器之后,根本没法共享给 switch。然后转战淘宝,发现有卖代理服务器的,就是给你个 IP+Port,先买个 1 块的试了试,下东西是很快,但是还是没法登陆狂野飙车,顺便看了下卖家给的服务器 IP 是美帝的。
然后想着能不能找个香港的服务器会好些,于是刚刚自己买了个阿里云国际的轻应用服务器,3.5$,搭建好之后,NAT 类型变成了 B,测速是 20Mbps 左右,几个朋友一起用,还是很合算的。
下面写下搭建过程,希望能帮得上有需要的人。如果有啥写错的,请轻喷~
#教程基于 CentOS
1.安装 Squid 并修改配置:
yum install squid -y
cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
vi /etc/squid/squid.conf
我的配置文件,主要是修改端口和添加认证信息:
#
# Recommended minimum configuration:
#
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
#http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
#http_access deny CONNECT !SSL_ports
# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
#http_access deny all
# Squid normally listens to port 3128
#http_port 3128
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
#用户认证文件的位置
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
#http 代理的端口,默认为 3128
http_port 12306
acl OverConnLimit maxconn 16 #定义每个 IP 最大允许 16 个连接,防止攻击
2.然后配置用户,为了安全:
先安装 httpd
yum install httpd* -y
添加用户:
htpasswd -c /etc/squid/passwd <username>
#然后输入密码。
重启 Squid 并启用开机启动:
systemctl restart squid
systemctl enable squid
3.测试:
先在 VPS 上本地测试下:
curl --proxy 127.0.0.1:PORT --proxy-user <username>:<password> http://www.baidu.com
如果有返回的话,应该就是 OK 了。
然后可以从其它 Linux 上测试下,记得在 VPS 管理的地方防火墙放通自己定义的 PORT:
curl --proxy <服务器 IP>:PORT --proxy-user <username>:<password> http://www.baidu.com
然后 Switch 只需要在连接 wifi 的地方配置好代理服务器 IP + PORT + User + Password,就能用了。
不保证每个地区都好用,具体的网络还是跟当地的情况有很大关系。阿里云这个机器带宽是 30M,我现在在杭州,网络是电信,测速有 20Mbps 左右,sShop 下载的时候,从服务器侧看,带宽跑到 17M 左右;朋友在重庆,测速只有 6Mbps,但是可以正常缓冲出舞力全开的在线歌曲。
Ps.也欢迎大家讨论其他更好用的方法。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.