HTTP Proxy 设置与使用指南
一 基础概念与准备
二 操作系统与命令行设置
set http_proxy=http://127.0.0.1:8118 与 set https_proxy=http://127.0.0.1:8118echo %http_proxy%set http_proxy= 与 set https_proxy=export http_proxy=http://127.0.0.1:8118 与 export https_proxy=http://127.0.0.1:8118export ALL_PROXY=socks5://127.0.0.1:1080unset http_proxy、unset https_proxy、unset ALL_PROXYgit config --global http.proxy http://127.0.0.1:8118 与 git config --global https.proxy http://127.0.0.1:8118git config --global --unset http.proxy 与 git config --global --unset https.proxyexport 写入 ~/.bashrc、~/.zshrc、~/.profile 或系统环境变量配置中。三 浏览器与桌面应用设置
四 开发语言与工具中的使用
os.environ['http_proxy'] = 'http://proxy.example.com:8080'os.environ['https_proxy'] = 'https://proxy.example.com:8443'proxies = {'http': 'http://proxy.example.com:8080', 'https': 'https://proxy.example.com:8443'}requests.get('http://example.com', proxies=proxies)http://user:pass@host:port,或使用 HTTPProxyAuth;如使用 SOCKS,安装 requests[socks] 后配置 socks5://。ProxyHandler 与 build_opener 全局设置代理,后续 urlopen 自动走代理。mkdir -p /etc/systemd/system/docker.service.d/etc/systemd/system/docker.service.d/http-proxy.conf,内容示例:
[Service]Environment="HTTP_PROXY=http://proxy.example.com:8080" "HTTPS_PROXY=https://proxy.example.com:8080" "NO_PROXY=localhost,127.0.0.1"systemctl daemon-reload && systemctl restart docker-x/--proxy,如 curl -x http://proxy.example.com:8080 https://example.comproxy=http://proxy.example.com:8080(如需认证可用 proxy=http://user:pass@host:port)http_proxy=... 与 https_proxy=...。五 验证与排错
curl -I https://httpbin.org/ip(配合 -x 指定代理测试)。source ~/.bashrc 或 systemctl daemon-reload && systemctl restart docker),以及是否重启了相关应用/终端会话。免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。