簡體   English   中英

在Nginx和NodeJS上配置HTTPS

[英]Configuring HTTPS on Nginx and NodeJS

我正在使用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)是什么?

謝謝!!

使用Nginx(和僅Nginx)用於SSL,這是標准。 正如您設置的那樣,Nginx作為反向代理工作,因此它將為您的程序提供端口443上給定加密數據的本地未加密數據,因此如果您還在節點程序上使用SSL,它將無法工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM