NPM安装通过使用UNABLE_TO_VERIFY_LEAF_SIGNATURE

时间:2018-07-30 12:13:04

标签: npm openssl reverse-proxy squid

我们有一个带SSL的Squid代理,使用自签名证书和ca-bundle.cert。尝试安装时,只有最近的NPM安装开始失败

npm --registry https://registry.npmjs.org \ --proxy http://localhost:10080 --https-proxy http://localhost:10443 \ --ddd install express

产生错误-

npm ERR! errno UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm ERR! request to https://registry.npmjs.org/express failed, 
reason: unable to verify the first certificate

Squid在Docker内部运行,并且日志显示

NONE/200 0 CONNECT registry.npmjs.org:443 - HIER_DIRECT

任何想法或指示都将不胜感激。

第一则回复

我在squid.conf中添加了“ dns_v4_first on”,现在NPM错误消息是

npm verb node v8.9.3
npm verb npm  v5.5.1
npm ERR! code SELF_SIGNED_CERT_IN_CHAIN
npm ERR! errno SELF_SIGNED_CERT_IN_CHAIN
npm ERR! request to https://registry.npmjs.org/express failed, reason: self signed certificate in certificate chain

其他信息

我发现NPM接受代理设置时出现异常行为。如下所示,将代理设置为嵌入式时,它将返回HTTP 503。

npm cache clear --force && rm -rf node_modules/

npm --strict-ssl=false --registry https://registry.npmjs.org 
--proxy http://example-proxy.net:3339 --https-proxy http://example-proxy.net:3339 
--ddd install express

仅设置代理而不使用https-proxy时,它起作用!

npm cache clear --force && rm -rf node_modules/

npm --strict-ssl=false --registry https://registry.npmjs.org 
--proxy http://example-proxy.net:3339  
--ddd install express

如果在外壳中而不是通过npm命令设置了代理,它将起作用!

export http_proxy=http://example-proxy.net:3339 
export HTTPS_PROXY=http://example-proxy.net:3339 
export https_proxy=http://example-proxy.net:3339 
export HTTP_PROXY=http://example-proxy.net:3339

npm cache clear --force && rm -rf node_modules/

npm --strict-ssl=false --registry https://registry.npmjs.org 
--ddd install express

那么当同时设置了代理和https-proxy时,为什么npm命令返回HTTP 503?

1 个答案:

答案 0 :(得分:1)

squid似乎正在尝试通过仅具有IPv4的主机上的IPv6进行连接:

connect(14, {sa_family=AF_INET6, sin6_port=htons(443), inet_pton(AF_INET6, "2400:cb00:2048:1::6810:1b23", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 ENETUNREACH (Network is unreachable)
read(14, 0x7ffe450e1040, 65535)         = -1 ENOTCONN (Transport endpoint is not connected)

将此选项添加到squid.conf中可对其进行修复:

dns_v4_first on