ElasticBeanStalk NGinx configuration for multiple ports in Nodejs

678 Views Asked by At

I have my nodejs hosted in ElastiCbean stalk environment. It uses the default configurations and default port. Now I am planning to open another port and listen to that port from Nodejs applicaiton. This is kind of opening nodejs in mutliple ports.

I have done the nodejs coding part.But i am not sure of the nginx changes to make it to listen to multiple ports. Can someone explain it to me?

1

There are 1 best solutions below

2
On

I've only configured nginx for Java backends, but essentially you will need to configure the server directive to include the additional port you want to listen on, such as:

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;
  }
}

So I recommend ssh on to your Nodejs EB server and fish around for your nginx config directories, looking for nginx, conf.d folders, or an nginx.conf file. When you find it, you can override the default server config, or apply an include statement to extend it, either way the server directive above should allow access on multiple ports as far as nginx is concerned.