HTTPS TLS设置在节点

问题描述 投票:2回答:1

我是通过我的代码库今天看,这台服务器并找到以下行的部分:

var https = require('https');
https.globalAgent.options.secureProtocol = 'TLSv1_2_method';

function createHttpsServer(app) {
    var https = require('https');
    var fs = require('fs');
    const options = {
        secureProtocol: 'TLSv1_2_method',
        // ...
    };
    var server = https.createServer(options, app);
    return server;
}

它看起来像代码的重复我,我不知道为什么这些做不同的事情(或他们?)。

我的一位同事告诉我,上面一个是控制来自的NodeJS,这反过来又为我们提供了访问其用于与客户端的HTTP请求万物https.agent提出HTTPS请求TLS。

这也是相比,在.NET世界ServicePointManager

所以,做这些方法都做不同的事情?在某些时候,我们的代码的作用:

var server = protocol === 'https' ? createHttpsServer(app) : createHttpServer(app);

那会不会使用相同的服务器在这一天结束了吗?

node.js tls1.2
1个回答
0
投票
var server = protocol === 'https' ? createHttpsServer(app) : createHttpServer(app);

上述行创建相同的服务器,唯一的区别是如果协议是“https”时,将HTTPS服务器(这需要SSL证书)上运行,而如果所述协议是http它将HTTP服务器上运行。

© www.soinside.com 2019 - 2024. All rights reserved.