【问题标题】:ElasticBeanStalk NGinx configuration for multiple ports in NodejsNodejs中多个端口的ElasticBeanStalk NGinx配置
【发布时间】:2018-05-18 07:45:25
【问题描述】:

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

我已经完成了 nodejs 编码部分。但我不确定 nginx 的更改是否使其能够监听多个端口。 谁能给我解释一下?

【问题讨论】:

    标签: node.js nginx amazon-elastic-beanstalk elastic-load-balancer


    【解决方案1】:

    我只为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;
      }
    }
    

    因此,我建议将 ssh 连接到您的 Nodejs EB 服务器并四处寻找您的 nginx 配置目录,寻找 nginxconf.d 文件夹或 nginx.conf 文件。当你找到它时,you can override the default server config, or apply an include statement to extend it,无论哪种方式,上面的server 指令都应该允许对 nginx 的多个端口进行访问。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 2018-12-31
    • 1970-01-01
    • 2017-05-30
    • 2019-01-12
    • 2021-05-10
    相关资源
    最近更新 更多