代理后面的 npm 失败,状态为 403 [英] npm behind a proxy fails with status 403

查看:45
本文介绍了代理后面的 npm 失败,状态为 403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在代理后面运行 npm.我试过直接或通过 Authoxy 进入代理:

I'm trying to run npm behind a proxy. I've tried both entering the proxy directly or through Authoxy:

npm config set proxy http://localhost:8999
npm config set https-proxy http://localhost:8999

无论我使用哪个代理,我在运行 npm search 时总是以同样的错误告终:

Regardless of which proxy I use, I always end up with the same error when running npm search:

npm info it worked if it ends with ok
npm verb cli [ 'node', '/usr/local/bin/npm', 'search' ]
npm info using npm@1.1.45
npm info using node@v0.8.4
npm verb config file /Users/xxx/.npmrc
npm verb config file /usr/local/etc/npmrc
npm verb config file /usr/local/lib/node_modules/npm/npmrc
npm WARN Building the local index for the first time, please be patient
npm verb url raw /-/all
npm verb url resolving [ 'https://registry.npmjs.org/', './-/all' ]
npm verb url resolved https://registry.npmjs.org/-/all
npm info retry registry request attempt 1 at 09:48:47
npm http GET https://registry.npmjs.org/-/all
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403
npm info retry registry request attempt 2 at 09:48:57
npm http GET https://registry.npmjs.org/-/all
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403
npm info retry registry request attempt 3 at 09:49:57
npm http GET https://registry.npmjs.org/-/all
npm ERR! Error: tunneling socket could not be established, sutatusCode=403
npm ERR!     at ClientRequest.onConnect (/usr/local/lib/node_modules/npm/node_modules/request/tunnel.js:148:19)
npm ERR!     at ClientRequest.g (events.js:185:14)
npm ERR!     at ClientRequest.EventEmitter.emit (events.js:115:20)
npm ERR!     at Socket.socketOnData (http.js:1383:11)
npm ERR!     at TCP.onread (net.js:410:27)

该命令总是以 sutatusCode [原文如此!] 403 失败 - 这意味着未经授权.我已将 Authoxy 设置为不需要用户名/密码.当我绕过 Authoxy 并以 http://user:pass@proxy:port 的形式为我们的 NTLM 代理提供真实代理凭据时,会发生同样的错误.

The command always fails with sutatusCode [sic!] 403 - which means unauthorized. I have set up Authoxy to not require a username/password. The same error happens when I bypass Authoxy and provide the real proxy credentials for our NTLM proxy in the form of http:// user:pass@proxy:port.

如何通过代理完成这项工作?

How can I make this work through the proxy?

更新

我在 NPM 项目上创建了一个问题来报告这个:https://github.com/isaacs/npm/issues/2866

I have created an issue on the NPM project to report this: https://github.com/isaacs/npm/issues/2866

推荐答案

好的,所以在发布问题后的几分钟内,我在这里找到了自己的答案:https://github.com/npm/npm/issues/2119#issuecomment-5321857

OK, so within minutes after posting the question, I found the answer myself here: https://github.com/npm/npm/issues/2119#issuecomment-5321857

问题似乎是 npm 在代理上使用 HTTPS 并不是那么好.将注册表 URL 从 HTTPS 更改为 HTTP 为我修复了它:

The issue seems to be that npm is not that great with HTTPS over a proxy. Changing the registry URL from HTTPS to HTTP fixed it for me:

npm config set registry http://registry.npmjs.org/

我仍然需要提供代理配置(在我的情况下通过 Authoxy),但现在一切正常.

I still have to provide the proxy config (through Authoxy in my case), but everything works fine now.

似乎是一个常见问题,但没有很好的文档记录.我希望这里的答案能让人们更容易找到他们是否遇到这个问题.

Seems to be a common issue, but not well documented. I hope this answer here will make it easier for people to find if they run into this issue.

这篇关于代理后面的 npm 失败,状态为 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆