Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为 NPM/Git/Bower 设置代理 #4

Open
huangtengfei opened this issue Mar 12, 2015 · 0 comments
Open

为 NPM/Git/Bower 设置代理 #4

huangtengfei opened this issue Mar 12, 2015 · 0 comments

Comments

@huangtengfei
Copy link
Owner

代理上网

在局域网内工作,可以通过 CCproxy 代理上网,具体教程可参考 此文,下文假设代理服务器地址为 10.24.48.6,端口为808.

为 NPM 设置代理

npm config set proxy http://10.24.48.6:808
npm config set https-proxy http://10.24.48.6:808

注意不要遗漏 "http://" ,否则可能安装某些 package 时可能会报:

ERR! Error: Invalid protocol

这个问题我在安装 hexo 时碰到过,后来参考 此文 解决。

如果代理需要认证的话可以这样来设置:

npm config set proxy http://username:password@server:port
npm config set https-proxy http://username:pawword@server:port

为 Git 设置代理

下载 git,并在系统 path 环境变量中配置。

git 的代理设置有两种办法,一是直接在命令行设置:

git config --global http.proxy http://10.24.48.6:808
git config --global https.proxy http://10.24.48.6:808

由于代理上网,git 协议不能用,所以需要设置来用 https 协议替代:

git config --global url."https://".insteadOf git://

如果执行

git clone https://....

报以下错误

error: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt 
CRLfile: none

说明证书校验有问题,可以设置:

git config --global http.sslverify false

方法二是直接修改 git 的配置文件 .gitconfig

[http]
    proxy = http://10.24.48.191:808
    sslverify = false
[https]
    proxy = http://10.24.48.191:808
[url "https://"]
    insteadOf = git://

关于 git 的使用可参考 此文

为 Bower 设置代理

bower 的安装和使用依赖于 npm 和 git,在完成前两者的代理设置后,有两种方法为 bower 设置代理。

方法一,直接修改 bower 的配置文件 .bowerrc,如果没有可先添加

  "proxy": "http://10.24.48.6:808",
  "https-proxy": "http://10.24.48.6:808"

方法二,在系统变量里添加 HTTP_PROXYHTTPS_PROXY

关于 bower 的使用可参考 此文

参考

npm的配置管理及设置代理
为git设置代理
设置 git/npm/bower/gem 镜像或代理的方法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant