6

I created the simple Node.js express tutorial and it runs locally. I setup my Azure Web App to pull the repo from BitBucket, which it does, but I'm getting the following error in LogFiles/Application:

Port 80 requires elevated privileges

Why would this be happening? Isn't node running at elevated privileges? If not, how do I configure it so it is?

UPDATE: IMPORTANT!!!

This is never clearly explained in any documentation that I saw...

Azure appears to be doing port forwarding for node.js applications. So when you hit your Azure URL on port 80/443 it gets forwarded to another port that your node.js application is running on. YOU DO NOT SET THAT PORT!! It is an environment variable managed by Azure so you simple listen at process.env.PORT. Done, that's it.

SomethingOn
  • 9,813
  • 17
  • 68
  • 107

4 Answers4

3

i assume you are using Azure App Service. Even from end-user perspective, request is thru port 80, you will need to update your app to listen on port that get from environment variable, a port which load-balancer will actually distribute request to.

See below tutorial for more details.

https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/

var http = require('http')
var port = process.env.PORT || 1337;
http.createServer(function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World\n');
}).listen(port);
Xiaomin Wu
  • 3,621
  • 1
  • 15
  • 14
  • 1
    You should probalby add that this doesn't mean that the end-user won't reach your service on port 80. They will. This is just one way a service with shared resources allows multiple web server processes to share hardware and some sort of proxy or load balancer out in front directs your requests to the port your server is actually running on. – jfriend00 Mar 24 '16 at 00:20
  • Using BitBucket deploy or Visual Studio publish to Azure my code makes it to the App Service, but I get the port 80 elevated privileges issue. Do I have to set something in web.config, package.json? I've never had problems deploying node to Heroku or AWS – SomethingOn Mar 24 '16 at 01:54
  • 1
    see my answer above, the key is your app need to listen on port "process.env.PORT". – Xiaomin Wu Mar 24 '16 at 05:18
  • Do we need to set the process.env.PORT environment variable or is this some sort of port forwarding that Azure is doing? – SomethingOn Mar 24 '16 at 14:47
  • 1
    it will be populated by Azure, you just need to consume it :) – Xiaomin Wu Mar 24 '16 at 17:21
2

I just fixed this. In my case it was due to set PORT = 80 in env variables (Application Settings). Once I removed PORT from there and let Azure automatically handle the port the error was gone.

Tulio Faria
  • 874
  • 7
  • 16
1

Use Nginx,

Nginx (pronounced "engine x") is a web server. It can act as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache.

It isn't good practice to run your application with root privileges or directly run your application on port 80.

Jay
  • 1,575
  • 1
  • 17
  • 22
0

Run the app with sudo. I would suggest you to check out this question. https://stackoverflow.com/a/16573737/5583278

Where the answer is to redirect the traffic from a nodejs port to port 80. Which will avoid having to run node as root.

Community
  • 1
  • 1