node.js - 如何修复端口 80 上的 Azure 应用服务错误?

标签 node.js azure express azure-web-app-service azure-appservice

我是 Azure 应用服务菜鸟 - 我认为这几乎是交 key 工程,但我遇到了一些端口问题。我已将 Node/Express Web 应用程序部署到应用程序服务...

当我在 Node/Express 应用程序中将端口指定为 80 并部署时,我无法访问该网站。当我进入控制台和 node app.js 时,收到错误“错误:listen eacces:权限被拒绝 0.0.0.0:80”

当我使用 3000 时,我收到一条错误,指出有其他东西正在监听 3000。

我是否指定了错误的端口?文档似乎说 80 是与 Azure 应用服务一起使用的两个端口之一。如何修复此错误或使用正确的端口是什么?

谢谢

编辑:它在 Windows 上的 Azure 应用服务内运行

最佳答案

When I go into console and node app.js, I get the error "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------> To check if any process running
tskill <Process_ID>------>to kill the process

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

<小时/>

我创建了一个示例 Nodejs/expressjs 应用程序来检查我的环境。 服务器代码:

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 中运行应用: enter image description here enter image description here

在端口 3000 中运行应用: enter image description here enter image description here

门户: enter image description here

关于node.js - 如何修复端口 80 上的 Azure 应用服务错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76031618/

相关文章:

reactjs - Azure B2C - 续订 session

Azure 容器实例 - 允许出站连接到互联网

azure - headless 浏览器和 Windows Azure 网站

node.js - 使用 node-cron 的 Cron 作业不会通过 console.log 进行测试

javascript - 使用 Node 的加密库创建自签名证书?

javascript - NodeJS 服务器无法处理多个用户

javascript - 无法读取未定义的属性 "cart",这是一个 session 属性

javascript - 如何用 Jest 模拟 knex 计数

javascript - 从回调中返回数据

node.js - 尽管使用与集线器所示相同的Dockerfile,但重建Docker镜像失败