我将我的网站配置为作为HTTPS / SSL网站运行。我的服务器是node.js,ssl由nginx
反向代理配置,具有以下配置:
server {
listen 443 ssl;
server_name example.co.id;
location / {
proxy_pass http://localhost:3000;
}
ssl on;
ssl_certificate /home/user/www.example.co.id/www_example_co_id.crt;
ssl_certificate_key /home/user/www.example.co.id/www.example.co.id.key;
ssl_prefer_server_ciphers on;
}
现在我想从node.js应用程序向该服务器请求REST数据。我使用request
库。我还直接从服务器下载www_example_co_id.crt
和www.example.co.id.key
。这是我的简单代码:
var path = require("path");
var fs = require("fs");
var request = require('request');
var certFile = path.resolve(__dirname, 'www_example_co_id.crt')
, keyFile = path.resolve(__dirname, 'www.example.co.id.key');
var options = {
url: 'https://example.co.id/api/movie/show',
agentOptions: {
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
passphrase: 'example',
securityOptions: 'SSL_OP_NO_SSLv3'
}
};
request.get(options, function(error){
console.log(error)
});
这是结果
Error: unable to verify the first certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1062:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:586:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:416:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
我尽可能多地搜索以解决此问题我尝试添加require('ssl-root-cas').inject();
但没有工作结果