【问题标题】:Configuring HTTPS on Nginx and NodeJS在 Nginx 和 NodeJS 上配置 HTTPS
【发布时间】:2017-06-08 14:28:33
【问题描述】:

我正在使用 Nginx 在端口 80 上发布静态内容,并使用 433 重定向(使用 SSL)到 NodeJS。 Nginx的配置如下:

server {
    listen 443 ssl;

    ssl_certificate /opt/projetos/nodejs-project-ssl/vectortowns-cert.pem;
    ssl_certificate_key /opt/projetos/nodejs-project-ssl/vectortowns-key.pem;
    ssl_protocols        SSLv3 TLSv1;
    ssl_ciphers HIGH:!aNULL:!MD5;

    server_name 127.0.0.1:443;

    location / {
            proxy_pass  https://127.0.0.1:8443;
            proxy_redirect off;
            proxy_set_header Host $host ;
            proxy_set_header X-Real-IP $remote_addr ;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
            proxy_set_header X-Forwarded-Proto https;
    }

}

使用 NodeJS、Express 和 EJS,我将动态内容发布到端口 8443,也配置为使用 HTTPS。请参阅下面的 javascript 代码(仅对问题重要的部分)。

// other codes...
/* Enable https */
var privateKey = fs.readFileSync('/opt/projetos/nodejs-project-ssl/vectortowns-key.pem');
var certificate = fs.readFileSync('/opt/projetos/nodejs-project-ssl/vectortowns-cert.pem');
var credentials = {
    key: privateKey,
    cert: certificate
};
// other codes...
/* Controllers */
app.use(require('./controllers'));
https.createServer(credentials, app).listen(
    configuration.server.port,
    configuration.server.address,
    function(){
        logger.info('Server started: ' + configuration.server.address + ':' + configuration.server.port);
});

我的问题是:

  1. 我需要在 Nginx 和 NodeJS 中配置 SSL 证书和密钥,还是只在其中一个中配置?
  2. 如果我只需要一个,最好的选择是什么(NodeJS 或 Nginx)?

谢谢!!

【问题讨论】:

    标签: node.js ssl nginx https


    【解决方案1】:

    对 SSL 使用 Nginx(和仅 Nginx),这是标准。正如您设置的那样,Nginx 充当反向代理,因此它将为您的程序提供本地未加密数据,用于端口 443 上给定的加密数据,因此如果您还在节点程序上使用 SSL,它将无法工作

    【讨论】:

    • 谢谢,我做错了。我现在调整一下:)
    猜你喜欢
    • 1970-01-01
    • 2016-08-23
    • 2019-03-16
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    相关资源
    最近更新 更多