blog
blog copied to clipboard
终端代理配置指南
macOS & Linux
éè¿è®¾ç½® http_proxyãhttps_proxyï¼å¯ä»¥è®©ç»ç«¯èµ°æå®ç代çã é ç½®èæ¬å¦ä¸ï¼å¨ç»ç«¯ç´æ¥æ§è¡ï¼åªä¼ä¸´æ¶çæï¼
# 设置代ç
export http_proxy=http://127.0.0.1:8899
export https_proxy=$http_proxy
# ææ¯ä¸è¡å½ä»¤
export https_proxy=http://127.0.0.1:8899 http_proxy=http://127.0.0.1:8899
# è¿å代ç
unset http_proxy https_proxy
8899
æ¯ http 代ç Whistle 对åºç端å£ï¼è¯·æ ¹æ®ä½ çå®é
æ
åµä¿®æ¹ã
Windows
以ä¸ä»£ççææ
åµåä½¿ç¨ curl -I http://www.google.com
è¿è¡éªè¯ã
Git Bash
设置æ¹æ³å "macOS & Linux"
# 设置代ç
export http_proxy=http://127.0.0.1:8899
export https_proxy=$http_proxy
# -I/âhead åªæ¾ç¤ºè¯·æ±å¤´ä¿¡æ¯
$ curl -I http://www.google.com
HTTP/1.1 200 OK
Connection: close
Transfer-Encoding: chunked
Cache-Control: private
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-93sLvK4rJwYE9FtSfUG6Zw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=ISO-8859-1
Date: Fri, 02 Feb 2024 02:07:31 GMT
Expires: Fri, 02 Feb 2024 02:07:31 GMT
P3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: 1P_JAR=2024-02-02-02; expires=Sun, 03-Mar-2024 02:07:31 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=Ae3NU9MS6jMZwtay0TsP0xRR63IAWlYgmabJzkTifIJB9fgipii_59R6s9M; expires=Wed, 31-Jul-2024 02:07:31 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=O8E9SUcRhRPHyBCTZef1vKSdwgVmWjAPzfytd_0Vg1TzfKQgNYwNqzViLd5mI7DX9hbGZfEH6JVUWXfA3cxQciyRx9RJnUIKJTWbOgJvz9LH0UP4uajkmLOUtcPq_sehwvLQ9si30UsZlIWAIiazfSRQWzsfCnd4U28xjPust8M; expires=Sat, 03-Aug-2024 02:07:31 GMT; path=/; domain=.google.com; HttpOnly
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0
# è¿å代ç
unset http_proxy https_proxy
$ curl -I http://www.google.com
curl: (28) Failed to connect to www.google.com port 80: Timed out
PowerShell
# PowerShell ä¸ç curl è¯æ³ï¼
curl.exe [options] <url>
# ä½ å¯ä»¥è¿è¡ä»¥ä¸å½ä»¤ä»¥è·åæå
³ curl å½ä»¤åå
¶é项ï¼ä¾å¦ -aã-C çï¼çæ´å¤ä¿¡æ¯â¦
curl.exe --help
# 设置代ç
$env:http_proxy="http://127.0.0.1:8899"
$env:https_proxy="http://127.0.0.1:8899"
curl.exe -I http://www.google.com
HTTP/1.1 200 OK
Connection: close
Transfer-Encoding: chunked
Cache-Control: private
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-0sRctw1-FGtkEYrRPuAQ_g' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Content-Type: text/html; charset=ISO-8859-1
Date: Fri, 02 Feb 2024 02:47:05 GMT
Expires: Fri, 02 Feb 2024 02:47:05 GMT
P3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: 1P_JAR=2024-02-02-02; expires=Sun, 03-Mar-2024 02:47:05 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=Ae3NU9PVYx8ZSnnCXgPFapze7dAPXGMkc2Jcm1lgzi3F6v-AlaQjbqtfL_U; expires=Wed, 31-Jul-2024 02:47:05 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=G2nL2I9u1NaiFioj97Xl8P5t7AwjJFXKwlQYzvvT_WzXvICMrp_52cNdKnEFZiyTtVEKLFfs_Cd0eqaUl6VKDP_mWvx3CiDDLiInIjRTcvolpcPqTv-fK7Ek_CoQKkXR8rObAJ4qcbUqVYFuFkzsc5DNQ3fEqawO_Olfy4-GRPU; expires=Sat, 03-Aug-2024 02:47:05 GMT; path=/; domain=.google.com; HttpOnly
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0
# è¿å代ç
$env:http_proxy=""
$env:https_proxy=""
curl.exe -I http://www.google.com
curl: (7) Failed to connect to www.google.com port 80: Timed out
cmd
注æï¼å¨ Windows ä¸ä½¿ç¨å ¨å±ä»£çæ¹å¼ä¸ä¼å¯¹ cmd çæ
# 设置代ç
set http_proxy=http://127.0.0.1:8899
set https_proxy=http://127.0.0.1:8899
# è¿å代ç
set http_proxy=
set https_proxy=
å ¶ä»ä»£ç设置
git 代ç
# æ¥çå
¨å±é
ç½®
git config --list
# 设置
git config --global http.proxy 'http://127.0.0.1:8899'
git config --global https.proxy 'https://127.0.0.1:8899'
# æ¢å¤
git config --global --unset http.proxy
git config --global --unset https.proxy
npm
# æ¥çå
¨å±é
ç½®
npm config list -g
# 设置
npm config set proxy http://127.0.0.1:8899 -g
npm config set https-proxy http://127.0.0.1:8899 -g
# æ¢å¤
npm config delete proxy
npm config delete https-proxy
åè
- https://zhuanlan.zhihu.com/p/357875811
- https://www.delftstack.com/zh/howto/powershell/run-curl-command-via-powershell/