[英]Node (keystonejs) address already in use error, but is not. Also EACCES error. NGINX behind
项目有keystonejs ,它是一个 Nodejs CMS。
突然(好吧,可能在尝试安装 SSL 证书后,停止并重新启动节点服务器和 nginx)它停止工作。
当我用我的非 root 用户尝试node keystone.js
,我有这个错误:
Error: listen EACCES
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at net.js:1143:9
at dns.js:72:18
at process._tickCallback (node.js:415:13)
当您尝试在端口 < 1024 上启动节点时会出现此错误,但事实并非如此,因为我在端口 3000 上有它。
当我以 root 身份尝试node keystone.js
,错误是:
我的项目无法启动:地址已被使用
请检查您是否还没有在指定端口上运行服务器。
我发现梯形文件中的错误字符串为EADDRINUSE
使用netstat -lntu
我检查了哪些端口正在使用,但:3000
没有。
也检查端口是否打开:
root@localhost:/home# sudo ufw status | grep 3000
3000 ALLOW Anywhere
3000 (v6) ALLOW Anywhere (v6)
我输入ps aux | grep node
ps aux | grep node
检查服务器上是否有 node/nodemon/forever 任务在运行。 只有一个节点在运行,与该项目无关。
root@localhost:/home# ps aux | grep node
server 30637 0.0 0.3 673840 25588 ? Ssl 11:15 0:00 /usr/bin/nodejs /usr/lib/node_modules/forever/bin/monitor keystone.js
server 30639 0.1 1.9 994280 156736 ? Sl 11:15 0:06 /usr/bin/nodejs /home/server/my-other-project/keystone.js
root 31503 0.0 0.0 11716 932 pts/1 S+ 12:28 0:00 grep --color=auto node
最后我认为EADDRINUSE
错误可能与服务器后面的nginx
端口有关(我将端口80
重定向到3000
)我检查是否有什么东西阻塞了该端口:
root@localhost:/home/# netstat -tulpn | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31266/nginx
tcp6 0 0 :::80 :::* LISTEN 31266/nginx
你知道为什么会这样吗?
首先,默认情况下 Keystone.JS 使用 3001 作为 https,所以你应该检查这个端口上是否有东西。
但我猜的问题是你在同一个端口上启动 http 和 https 服务器。 要仅使用 https,请在选项中指定:
...
'ssl' : 'only',
...
如果您想同时使用两个服务器(http 和 https),最好同时指定两个端口:
...
'ssl' : true, // launch http and https
'port' : 3000, // for http
'ssl port' : 3001 // for https
'ssl key' : 'your key.pem',
'ssl cert' : 'your cert.crt',
...
我猜你正在做下面的 conf ,你会得到你的错误,因为默认情况下,keystone http 在 3000 上启动,你在 3000 上映射 https 而不说如何处理 http:
...
'ssl' : true, // launch http and https
'ssl port' : 3000, // you launch https on the default http port and do not specify the http port -> error : 'Please check you are not already running a server on the specified port.'
'ssl key' : 'your key.pem',
'ssl cert' : 'your cert.crt',
...
这是文档: http : //keystonejs.com/docs/configuration/#options-ssl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.