简体   繁体   中英

Node (keystonejs) address already in use error, but is not. Also EACCES error. NGINX behind

Project has keystonejs which is a Nodejs CMS.

Suddenly (well, probably after try to install SSL certificates, stop and start again the node server and nginx) it stops working.

When I try node keystone.js with my no-root user I have this error:

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)

This error appears when you try to start node on a port < 1024 but is not the case because I have it on port 3000.

When I try node keystone.js as root the error is:

my-project failed to start: address already in use

Please check you are not already running a server on the specified port.

I found that error string in keystone files as EADDRINUSE

With netstat -lntu I cheked which ports are in use but :3000 is not.

Checked too if port is open:

root@localhost:/home# sudo ufw status | grep 3000
3000                       ALLOW       Anywhere
3000 (v6)                  ALLOW       Anywhere (v6)

I typed ps aux | grep node ps aux | grep node to check if there is a node/nodemon/forever task running on the server. There is only one node running that is not related with this project.

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

Finally I thought EADDRINUSE error may be related with the port of nginx that is behind the server (I redirect port 80 to 3000 ) I check if something is blocking that port:

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  

Do you have any idea why this happens?

First, by default Keystone.JS is using 3001 for https, so you should check if there is something on this port.

But the problem I guess is that you are launching http and https server on the same port. To use only the https, specify in your options :

...
'ssl' : 'only',
...

if you want to use both servers (http and https), it is better to specify both ports :

...
'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',
...

I guess you are doing the conf below and you will get the error you have because by default keystone http is launched on 3000 and you map https on 3000 without saying what to do with 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',
...

Here is the doc : http://keystonejs.com/docs/configuration/#options-ssl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM