You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Beget主机运行Express服务器遭遇listen EPERM权限错误求助

问题:Beget主机运行Express服务器出现EPERM错误

使用Beget主机搭建Express服务器,编写的app.js代码如下:

const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);

app.get('/', (req, res) => {
  res.send('<h1>Hello world</h1>');
});

server.listen(3000, () => {
  console.log('listening on *:3000');
});

运行后终端输出错误信息如下:

(docker) s999922k_ssh@splinter:~/io.s999922k.beget.tech [0] $ node app/app.js
node:events:505
      throw er; // Unhandled 'error' event
      ^

Error: listen EPERM: operation not permitted :::8080
    at Server.setupListenHandle [as _listen2] (node:net:1380:16)
    at listenInCluster (node:net:1428:12)
    at Server.listen (node:net:1516:7)
    at Object.<anonymous> (/home/s/s999922k/io.s999922k.beget.tech/app/app.js:10:8)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1407:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EPERM',
  errno: -1,
  syscall: 'listen',
  address: '::',
  port: 3000
}

Node.js v17.9.0

此前使用hostland.pro主机,通过Passenger运行同类服务未出现此问题,请问该错误的原因是什么?


答案

错误核心是EPERM: operation not permitted,原因主要有两点:

  • 共享主机端口限制:Beget的共享主机环境对用户监听端口有严格管控,即使3000是非特权端口(1024以上),平台也不允许用户直接启动监听端口的服务——共享主机是多用户环境,直接监听端口会引发资源冲突和安全风险,因此平台禁用了用户层面的端口监听权限。
  • 运行方式差异:之前在hostland.pro用Passenger运行时,Passenger作为应用服务器会统一处理端口映射和请求转发,不需要你手动指定监听端口;而现在直接用node app.js启动服务,试图自行监听3000端口,这在Beget的环境中是不被允许的操作。

对应的解决方向:

  • 改用Beget官方支持的部署方式,比如使用平台提供的Node.js应用管理工具,或配置Passenger(若平台支持)部署Express应用,这类方式会由平台自动处理端口分配和请求转发,无需你手动指定端口。
  • 若需手动运行,先确认Beget分配给你的可用端口范围,将server.listen(3000)替换为平台指定的端口,同时需通过主机的反向代理配置让外部请求能访问到你的服务。

内容的提问来源于stack exchange,提问作者Amstel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 10:17:18