我正在开发一个Nodejs应用程序,并使用pm2和Nginx在AWS ubuntu示例上托管。应用程序出现问题,所以我检查pm2 logs
,发现了这个
0|index | Error: listen EACCES: permission denied 0.0.0.0:300
0|index | at Server.setupListenHandle [as _listen2] (node:net:1723:21)
0|index | at listenInCluster (node:net:1788:12)
0|index | at Server.listen (node:net:1876:7)
0|index | at Function.listen (/home/ubuntu/twitter-helper/nodejs/node_modules/express/lib/application.js:635:24)
0|index | at Object.<anonymous> (/home/ubuntu/twitter-helper/nodejs/index.js:353:5)
0|index | at Module._compile (node:internal/modules/cjs/loader:1254:14)
0|index | at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
0|index | at Module.load (node:internal/modules/cjs/loader:1117:32)
0|index | at Module._load (node:internal/modules/cjs/loader:958:12)
0|index | at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23) {
0|index | code: 'EACCES',
0|index | errno: -13,
0|index | syscall: 'listen',
0|index | address: '0.0.0.0',
0|index | port: 300
0|index | }
问题是我在应用程序的任何地方都没有使用端口300,所以我不知道这个端口号是从哪里来的,如何修复它?
我的nodejs代码:
const PORT = process.env.PORT || 3001
app.listen(PORT, ()=>{console.log(`listen on port ${PORT}`)})
Nginx配置:
server {
listen 80;
listen [::]:80;
root /home/ubuntu/app/react/frontend/build;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name something something here;
location / {
try_files $uri /index.html;
}
location /api {
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
1条答案
按热度按时间k5hmc34c1#
非特权用户(非root)无法在低于1024的端口上打开侦听套接字。
不幸的是,除非您以root身份登录,否则通常必须使用以下URL
http://ip:port-其中端口号〉1024。
查看https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps#give-safe-user-permission-to-use-port-80
使用此命令
sudo apt-get install libcap2-bin