CentOS编译代码时,会有访问github代码的需求,服务器本身设置代理只是编译临时使用,加上服务器本身设置比较麻烦。可以通过服务器连接本地可访问的电脑进行连接,由于Mac可安装相关功能,主要为Linux系统和虚拟机准备
查看代理功能是否正常使用
本文主要以ClashX为例,其他需要自行探索,可以看到本机设置
- 设置允许局域网连接
- 查看端口,Http Socks 为7890
- 查看IP 192.168.1.11
- 确认服务器可连通代理机器(ping 192.168.1.11)
Git设置
socks5方式代理,global 为全局代理
git config --global http.proxy 'socks5://192.168.1.11:7890'
git config --global https.proxy 'socks5://192.168.1.11:7890'
http方式代理
git config --global http.proxy "http://192.168.1.11:7890"
git config --global https.proxy "http://192.168.1.11:7890"
取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
终端设置
no_proxy为不设置代理的网段
export http_proxy=socks5://192.168.1.11:7890
export https_proxy=socks5://192.168.1.11:7890
export ftp_proxy=socks5://192.168.1.11:7890
export no_proxy="192.168.1.11"
确保生效,需要重启 terminal
取消代理
unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy
通过 curl -i http://google.com 进行测试是否成功
失败内容
curl: (7) Failed to connect to google.com port 80: Operation timed out
生效内容
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Cross-Origin-Opener-Policy-Report-Only: same-origin-allow-popups; report-to="gws"
Report-To: {"group":"gws","max_age":2592000,"endpoints":[{"url":"https://csp.withgoogle.com/csp/report-to/gws/other"}]}
Date: Mon, 09 Jan 2020 03:28:19 GMT
Expires: Wed, 08 Feb 2020 03:28:19 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
评论区