如何修复Azure应用服务在端口80上出现错误?

huangapple go评论70阅读模式
英文:

How do I fix Azure App Service Erroring on Port 80?

问题

I'm an Azure App Service noob - I thought it would be pretty much turnkey, but I'm having some port issues it looks like. I've deployed a Node/Express web app to App Service...

当我在我的 Node/Express 应用中指定端口为 80 并部署时,我无法访问网站。当我进入控制台并运行 node app.js 时,我收到错误消息 "Error: listen eacces: permission denied 0.0.0.0:80"

当我使用端口 3000 时,我收到一个错误,指出另一个应用正在监听端口 3000。

我是否指定了错误的端口?文档似乎说 80 是 Azure App Service 中要使用的两个端口之一。如何修复此错误或应使用哪个正确的端口?

谢谢

Edit: 这在 Azure App Service 中的 Windows 上运行

英文:

I'm an Azure App Service noob - I thought it would be pretty much turnkey, but I'm having some port issues it looks like. I've deployed a Node/Express web app to App Service...

When I designate the port to 80 in my Node/Express app and deploy, I can't reach the website. When I go into console and node app.js, I get the error "Error: listen eacces: permission denied 0.0.0.0:80"

When I've used 3000, I get an error that states something else is listening on 3000.

Am I designating incorrect ports? Documentation seems to say that 80 is one of two ports to use with Azure App Service. How do I fix this error or what is the correct port to use?

Thank you

Edit: This running on Windows inside of Azure App Service

答案1

得分: 1

当我进入控制台并运行node app.js时,我收到错误消息"Error: listen eacces: permission denied 0.0.0.0:80"。

这个错误表示应用程序试图在端口80上进行监听,这需要提升的权限。

  • 在Azure应用服务中,应该使用PORT环境变量提供的端口。
  • 可以在生成的Express应用程序的脚本bin/www中找到这个环境变量,如下所示:
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

要解决这个问题,你可以将Node/Express应用程序中的端口更改为使用PORT环境变量。
你还可以运行以下命令来检查是否有另一个进程在端口3000上运行,如SO中所述:

netstat -ano | findstr :3000------> 检查是否有任何进程在运行
tskill <Process_ID>------> 杀死该进程

如果在端口3000上有另一个进程在运行,你可以要么停止该进程,要么在Node/Express应用程序中使用不同的端口。

我已经创建了一个示例的Node.js/Express.js应用程序来在我的环境中进行检查。
服务器代码:

var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});

var port = process.env.PORT || 3000;
app.listen(port, function () {
console.log('Example app listening on port ' + port + '!');
});

结果:

在端口80上运行应用程序:
如何修复Azure应用服务在端口80上出现错误?
如何修复Azure应用服务在端口80上出现错误?

在端口3000上运行应用程序:
如何修复Azure应用服务在端口80上出现错误?
如何修复Azure应用服务在端口80上出现错误?

门户:
如何修复Azure应用服务在端口80上出现错误?

英文:

>When I go into console and node app.js, I get the error "Error: listen eacces: permission denied 0.0.0.0:80"

The error indicates that the app is trying to listen on port 80, which requires elevated privileges.

  • In Azure App Service, the port provided by the PORT environment variable should be used.
  • This environment variable can be found in the script bin/www in your generated Express app as shown below:
var  port = normalizePort(process.env.PORT || &#39;3000&#39;);
app.set(&#39;port&#39;, port);

To fix the issue, you can change the port in your Node/Express app to use the PORT environment variable.
You can also check if there is another process running on port 3000 by running the below command as mentioned in SO:

netstat -ano | findstr :3000------&gt; To check if any process running
tskill &lt;Process_ID&gt;------&gt;to kill the process

If there is another process running on port 3000, you can either stop that process or use a different port in your Node/Express app.


I have created a sample nodejs/expressjs application to check in my environment.
Server code:

var  express = require(&#39;express&#39;);
var  app = express();  
app.get(&#39;/&#39;, function (req, res) {
res.send(&#39;Hello World!&#39;);
});

var  port = process.env.PORT || 3000;  
app.listen(port, function () {
console.log(&#39;Example app listening on port &#39; + port + &#39;!&#39;);
});

Result:

Running the app in port 80:
如何修复Azure应用服务在端口80上出现错误?
如何修复Azure应用服务在端口80上出现错误?

Running the app in port 3000:
如何修复Azure应用服务在端口80上出现错误?
如何修复Azure应用服务在端口80上出现错误?

Portal:
如何修复Azure应用服务在端口80上出现错误?

huangapple
  • 本文由 发表于 2023年4月17日 11:57:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定