首页 > 技术文章 > windows下 git cmd npm 的代理设置

yiting 2019-11-23 21:38 原文

  linux的比较简单,直接修改配置文件即可,这里就不再赘述。

  一、git 代理

  1. 临时 http 代理

# 地址和端口换成自己的代理服务器
export http_proxy=http://127.0.0.1:7777
export https_proxy=http://127.0.0.1:7777

  2. 永久 http 代理

# 命令方式 
git config --global http.proxy http://127.0.0.1:50015
git config --global https.proxy http://127.0.0.1:50015
# 修改配置文件方式
# 进入用户名根路径,找到 .gitconfig 文件,修改为

[http]
proxy = http://127.0.0.1:50015
[https]
proxy = http://127.0.0.1:50015

  3. 查看 http(s) 代理情况

git config --get --global http.proxy
git config --get --global https.proxy

  4. 永久 socks5 代理

命令方式:
git config --global http.proxy socks5://127.0.0.1:50014
git config --global https.proxy socks5://127.0.0.1:50014
修改配置文件方式:
进入用户名根路径,找到 .gitconfig 文件,修改为:

[http]
proxy = socks5://127.0.0.1:50015
[https]
proxy = socks5://127.0.0.1:50015

  5. 查看 socks5 代理情况

git config --get --global http.proxy
git config --get --global https.proxy
git config --get --global http.proxy socks5
git config --get --global https.proxy socks5

  6. 取消 http 或 socks 代理

git config --system (或 --global 或 --local) --unset http.proxy
例:
git config --global --unset http.proxy
git config --global --unset https.proxy

  

-------------------------------------------------------------------------   华丽的分隔线  -------------------------------------------------------------------------

  

  二、cmd 代理

  1. cmd http 代理

# cmd临时代理方案(cmd窗口关闭,则代理失效)
set http_proxy=http://127.0.0.1:50015
set https_proxy=http://127.0.0.1:50015
# cmd永久代理方案
netsh winhttp import proxy source=ie

  2. cmd socks5 代理

set http_proxy=socks5://127.0.0.1:50014
set https_proxy=socks5://127.0.0.1:50014

  3. cmd (服务器)针对性代理,绕过本地请求(修改为自己的代理地址和端口)

# http 
netsh winhttp set proxy proxy-server="http=192.168.17.100:50015" bypass-list="localhost"
# https
netsh winhttp set proxy proxy-server="http=192.168.17.100:50015" bypass-list="localhost"
# socks
netsh winhttp set proxy proxy-server="socks=192.168.17.100:50015" bypass-list="localhost"

  4. cmd 查看代理情况

netsh winhttp show proxy

  5. cmd 取消代理情况

netsh winhttp reset proxy

  

-------------------------------------------------------------------------   华丽的分隔线  -------------------------------------------------------------------------

  

  三、npm 代理设置

# 设置http代理
npm config set proxy=http://代理服务器地址:8080

# 取消代理
npm config delete proxy

# npm设置淘宝镜像
npm config set registry=https://registry.npm.taobao.org

# npm取消淘宝镜像
npm config delete registry

# 查看代理信息(当前配置)
npm config list

 

推荐阅读