ElasticBeanStalk中Node.js多端口NGinx配置

3

我将我的Nodejs托管在ElastiCbean Stalk环境中。 它使用默认配置和默认端口。 现在,我计划打开另一个端口,并从Nodejs应用程序监听该端口。这是一种在多个端口上打开nodejs的方式。

我已经完成了Nodejs编码部分。但我不确定如何更改nginx以使其监听多个端口。 有人能给我解释一下吗?

1个回答

0

我只为Java后端配置了nginx,但基本上您需要配置server指令以包括您想要侦听的其他端口,例如:

server {
  # listen for the extra the port the load balancer is forwarding to
  listen        88;
  access_log    /var/log/nginx/access.log main;

  client_header_timeout 60;
  client_body_timeout   60;
  keepalive_timeout     60;
  gzip                  off;
  gzip_comp_level       4;

  location / {
    # forward to the actual port the application runs on
    proxy_pass          http://127.0.0.1:8888;
    proxy_http_version  1.1;

    proxy_set_header    Connection          $connection_upgrade;
    proxy_set_header    Upgrade             $http_upgrade;
    proxy_set_header    Host                $host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
  }
}

所以我建议通过ssh登录到您的Nodejs EB服务器,并搜索nginx配置目录,查找nginxconf.d文件夹或nginx.conf文件。当您找到它时,您可以覆盖默认的server配置,或应用include语句来扩展它, 无论哪种方式,nginx上面的server指令都应该允许访问多个端口。


它不像Java环境一样有“includes”,您必须使用自定义配置:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html - JBaczuk
谢谢,我把我的回答概括了一下。 - ecoe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接