针对Nodejs中多个端口的ElasticBeanStalk NGinx配置

问题描述 投票:3回答:1

我在ElastiCbean stalk环境中托管了我的nodejs。它使用默认配置和默认端口。现在我打算打开另一个端口并从Nodejs应用程序中侦听该端口。这是在多个端口中打开nodejs。

我已经完成了nodejs编码部分。但我不确定nginx的更改是否使它能够监听多个端口。有人可以向我解释一下吗?

node.js nginx elastic-beanstalk amazon-elastic-beanstalk elastic-load-balancer
1个回答
0
投票

我只为Java backends配置了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;
  }
}

因此,我建议您在您的Nodejs EB服务器上使用ssh并查找nginx配置目录,查找nginxconf.d文件夹或nginx.conf文件。当你找到它时,you can override the default server config, or apply an include statement to extend it,无论是哪种方式,上面的server指令应该允许访问多个端口,就nginx而言。

© www.soinside.com 2019 - 2024. All rights reserved.