如何在SSL网站上使用请求?

时间:2017-10-31 08:34:40

标签: node.js ssl nginx

我将我的网站配置为作为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.crtwww.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();但没有工作结果

0 个答案:

没有答案