2017-01-23 52 views
2

我正在使用Nginx在端口80上發佈靜態內容,並將433重定向(使用SSL)重定向到NodeJS。 Nginx的配置如下:在Nginx和NodeJS上配置HTTPS

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)?

謝謝!

回答

7

對於SSL,使用Nginx(和Nginx),這是標準。如你所設置的,Nginx作爲一個反向代理,因此它會給你的程序提供本地未加密的數據,用於端口443上給定的加密數據,所以如果你還在你的節點程序中使用SSL,它將不起作用

+0

謝謝,我做錯了。我現在會調整:) – lgapontes