How to safely start a Node.js server on port 80 with Amazon Elastic Beanstalk?

The following error is common for people trying to start the Node.js server on port 80.

Error: listen EACCES 0.0.0.0:80 

I used this solution on my Amazon EC2 server, just using

 sudo node app.js 

Now I learned not to use this method for security problems. A good solution described in this answer is to use:

 sudo apt-get install libcap2-bin sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\`` 

However, I'm not sure how to implement any solution on an AWS Elastic Beanstalk instance, where I don't have access to SSH like I did for the AWS EC2 server, and the only way I seem to be running something in my package.json file package.json as follows:

 { "scripts": { "start": "node init" } } 

Therefore, I have no idea how I will run other types of commands. How it's done?

+5
source share
2 answers

Beanstalk has a built-in proxy server that listens on port 80. Node.js should only listen on process.env.PORT . Once this is done, you will be fine.

+9
source

An elastic beanstalk will forward requests to your instances (default port 80) from its load balancer. Thus, if you want to open a specific port, you can add an entry to the load balancing listeners with the load balancing port as your desired port and instance port as 80.
Hope this helps. If necessary, can clarify.

-1
source

Source: https://habr.com/ru/post/1258279/


All Articles