2015-09-23 41 views
1

我读过有关这个错误不同的答案,但要安装猫鼬npm install mongoose时我无法摆脱它,我得到以下错误:猫鼬安装 - 无法验证第一个证书

[email protected]:/var/www/html/test$ npm install mongoose --save-dev 
- 
> [email protected] install /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos 
> (node-gyp rebuild) || (exit 0) 

gyp WARN install got an error, rolling back install 
gyp ERR! configure error 
gyp ERR! stack Error: unable to verify the first certificate 
gyp ERR! stack  at Error (native) 
gyp ERR! stack  at TLSSocket.<anonymous> (_tls_wrap.js:1000:38) 
gyp ERR! stack  at emitNone (events.js:67:13) 
gyp ERR! stack  at TLSSocket.emit (events.js:166:7) 
gyp ERR! stack  at TLSSocket._finishInit (_tls_wrap.js:567:8) 
gyp ERR! System Linux 3.13.0-55-generic 
gyp ERR! command "/home/vagrant/.nvm/versions/node/v4.1.1/bin/node" "/home/vagrant/.nvm/versions/node/v4.1.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" 
gyp ERR! cwd /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos 
gyp ERR! node -v v4.1.1 
gyp ERR! node-gyp -v v3.0.3 
gyp ERR! not ok 
[email protected] node_modules/mongoose 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] ([email protected], [email protected]) 
└── [email protected] ([email protected], [email protected], [email protected]) 

我运行一个新的流浪汉箱ubuntu/trusty64落后企业的SSL代理,这里有我的代理服务器配置:

envvars中

$HTTPS_PROXY=http://user:[email protected]:port 
$HTTP_PROXY=http://user:[email protected]:port 

〜/ .npmrc

https-proxy=http://user:[email protected]:port 
proxy=http://user:[email protected]:port 
ca=/etc/ssl/certs/acme.pem 
cafile=/etc/ssl/certs/acme.pem 

证书是可信的,无论是故宫&卷曲的伟大工程

我怎么会尝试修复错误

sudo apt-get install build-essential 
npm install -g node-gyp 

--verbose错误日志

npm info install [email protected] 

> [email protected] install /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos 
> (node-gyp rebuild) || (exit 0) 

gyp info it worked if it ends with ok 
gyp verb cli [ '/home/vagrant/.nvm/versions/node/v4.1.1/bin/node', 
gyp verb cli '/home/vagrant/.nvm/versions/node/v4.1.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js', 
gyp verb cli 'rebuild' ] 
gyp info using [email protected] 
gyp info using [email protected] | linux | x64 
gyp verb command rebuild [] 
gyp verb command clean [] 
gyp verb clean removing "build" directory 
gyp verb command configure [] 
gyp verb check python checking for Python executable "python2" in the PATH 
gyp verb `which` succeeded python2 /usr/bin/python2 
gyp verb check python version `python2 -c "import platform; print(platform.python_version());"` returned: "2.7.6\n" 
gyp verb get node dir no --target version specified, falling back to host node version: 4.1.1 
gyp verb command install [ '4.1.1' ] 
gyp verb install input version string "4.1.1" 
gyp verb install installing version: 4.1.1 
gyp verb install --ensure was passed, so won't reinstall if already installed 
gyp verb install version not already installed, continuing with install 4.1.1 
gyp verb ensuring nodedir is created /home/vagrant/.node-gyp/4.1.1 
gyp verb created nodedir /home/vagrant/.node-gyp/4.1.1 
gyp http GET https://nodejs.org/dist/v4.1.1/node-v4.1.1-headers.tar.gz 
gyp verb download using proxy url: "http://usr:[email protected]:port/" 
gyp WARN install got an error, rolling back install 
gyp verb command remove [ '4.1.1' ] 
gyp verb remove using node-gyp dir: /home/vagrant/.node-gyp 
gyp verb remove removing target version: 4.1.1 
gyp verb remove removing development files for version: 4.1.1 
gyp ERR! configure error 
gyp ERR! stack Error: unable to verify the first certificate 
gyp ERR! stack  at Error (native) 
gyp ERR! stack  at TLSSocket.<anonymous> (_tls_wrap.js:1000:38) 
gyp ERR! stack  at emitNone (events.js:67:13) 
gyp ERR! stack  at TLSSocket.emit (events.js:166:7) 
gyp ERR! stack  at TLSSocket._finishInit (_tls_wrap.js:567:8) 
gyp ERR! System Linux 3.13.0-55-generic 
gyp ERR! command "/home/vagrant/.nvm/versions/node/v4.1.1/bin/node" "/home/vagrant/.nvm/versions/node/v4.1.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" 
gyp ERR! cwd /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos 
gyp ERR! node -v v4.1.1 
gyp ERR! node-gyp -v v3.0.3 
gyp ERR! not ok 

回答

2

很有可能是您的代理服务器更改了SSL证书(以便能够嗅探您的流量),从而使证书无效。 要解决此添加另一个环境变量: NODE_TLS_REJECT_UNAUTHORIZED=0

要小心,虽然,因为这改变了全球行为的NodeJS,迫使它忽略任何未经授权的证书。

+1

实际上,我的代理更改了证书,但是证书在我的环境中是可信的,并且节点知道它'ca =/etc/ssl/certs/acme.pem' cafile =/etc/ssl/certs/acme.pem ' – kitensei