node.js - nginx代理传递 Node ,SSL?

标签 node.js nginx reverse-proxy

我的 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/

相关文章:

apache - 如何在子域中的反向代理后面运行PrimeFaces?

node.js - Clasp登录失败: "Error retrieving access token..."

nginx 别名+位置指令

nginx - 使用 NGINX auth_request 和 oauth2_proxy 设置 header

tomcat - 如何使用spring boot将根上下文映射到嵌入式tomcat中的webapp上下文

nginx - 如何在 jwilder/nginx-proxy 中监听 443 端口

Node.js w/在回调中表达错误处理

node.js - 继承 - React 和 Webpack 中的 CSS 模块

node.js - 检查redis变量是否在nodejs中从外部更改

php - 带有 Vagrant 的 LEMP 堆栈 - 无法安装 Php5-fpm/Nginx?