Node.js在Linux中使用80端口报错

Node.js在Linux中使用80端口报错

  由于服务器用的CentOS8,为便于开发部署将本地环境换为了Linux。
  使用SVN将项目检出配置完成执行npm run dev时报错:

FATAL listen EACCES: permission denied 0.0.0.0:80
at Server.setupListenHandle [as _listen2] (net.js:1296:21)
at listenInCluster (net.js:1361:12)
at doListen (net.js:1498:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
✖ Nuxt Fatal Error
Error: listen EACCES: permission denied 0.0.0.0:80
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! xxx dev: nuxt
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xxx.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/xxx/.npm/_logs/xxx-debug.log
Node.js在Linux中使用80端口报错

解决方案

  一开始怀疑时80端口被占用了,但查看端口信息后发现80并没有被占用,那应该就是没有使用80端口的权限了。简单的处理办法就是加sudo提权。

  npm run dev换成sudo npm run dev