簡體   English   中英

Node (keystonejs) address already in use 錯誤,但不是。 還有 EACCES 錯誤。 NGINX 背后

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM