nginx代理传递节点,SSL? [英] nginx proxy pass Node, SSL?

查看:74
本文介绍了nginx代理传递节点,SSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的nginx服务器实际上是通过以下简单的代理来代理我的节点后端(侦听端口3000):

my nginx server is actually proxying my node backend (which listens on port 3000) with a simple:

location /api/ {
proxy_pass http://upstream_1;
}

其中上游_1是我在nginx.conf中(在端口3000上)定义的节点集群.

Where upstream_1 is my node cluster defined in nginx.conf (on port 3000).

我将不得不通过http连接添加SSL,所以我有以下问题:我是否只需要配置nginx来启用ssl?并且它将自动解密"请求并将未解密的请求传递给Node,后者将能够正常处理该请求?还是我需要将Nodejs配置为也支持ssl?

I'm gonna have to add SSL over http connections, so I have the following question: do I only need to configure nginx to enable ssl? And it will automatically "uncrypt" the request and pass it uncrypted to Node which will be able to handle it normally? Or do I need to configure Nodejs to support ssl as well?

推荐答案

如果您使用nginx来处理SSL,则您的节点服务器将仅使用http.

If you're using nginx to handle SSL, then your node server will just be using 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; 
      } 
   }

这篇关于nginx代理传递节点,SSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆