我的 nginx 服务器实际上是用一个简单的代理我的 Node 后端(监听端口 3000):
location /api/ {
proxy_pass http://upstream_1;
}
其中 upstream_1 是我在 nginx.conf 中定义的 Node 集群(在端口 3000 上)。
我将不得不通过http连接添加SSL,所以我有以下问题:我只需要配置nginx来启用ssl吗?它会自动“解密”请求并将其未加密传递给能够正常处理它的 Node 吗?或者我是否也需要配置 Nodejs 以支持 ssl?
最佳答案
如果您使用 nginx 来处理 SSL,那么您的 Node 服务器将只使用 http。
upstream nodejs {
server 127.0.0.1:4545 max_fails=0;
}
server {
listen 443;
ssl on;
ssl_certificate newlocalhost.crt;
ssl_certificate_key newlocalhost.key;
server_name nodejs.newlocalhost.com;
add_header Strict-Transport-Security max-age=500;
location / {
proxy_pass http://nodejs;
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;
}
}
关于node.js - nginx代理传递 Node ,SSL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10375659/