How to run node.js on port 80 on linux server?

When I try to run node on port 80, the error tells me that the port is in use. I assume Apache.

What is the proper way to β€œtake over” port 80 and save it this way after restarting the server?

(Linux xxxx.__.com 2.6.32-5-amd64 # 1 SMP Tue Jun 14 09:42:28 UTC 2011 x86_64 GNU / Linux)

+4
source share
5 answers

you can use ip tables to display ports from 80 to 8000

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000 

to make it permanent

 sudo sh -c "iptables-save > /etc/iptables.rules" 

and add

 pre-up iptables-restore < /etc/iptables.rules 

to your / etc / network / interfaces

+10
source

To capture port 80 when another process is listening on it, you must kill the process (or somehow tell it to stop listening). To make sure Apache is not trying to listen on port 80 again, the next time it starts, you need to edit its configuration or prevent it from starting.

To find out which process is listening on port 80, run sudo netstat -ntap and find the line with Local Address ending in port :80 . The process PID (and name) is in the rightmost column.

+2
source

you can use node.js with node-http-proxy check this link How to use vhosts with node-http-proxy? and How to run node.js on port 80?

Thanks and respect,
Alok

+1
source

Constantly working unused apache, perhaps a security hole, in any case, it makes no sense to start unused services.

In case you are on ubuntu, this is what I used ..

 sudo service apache2 stop sudo update-rc.d apache2 remove 
+1
source

You can access port 80 after stopping the service that is currently using it.

In your case, follow these steps:

1) Use systemctl to stop apache2:

 sudo systemctl stop apache2 

2) Check the status of apache2:

 sudo systemctl status apache2 

Or just enter http://localhost into your browser. If you get an error message, you will be fine.

 ERR_CONNECTION_REFUSED 

3) Now start your NodeJS server on port 80.

4) You can access your server at http://localhost

UPDATE

If you see errors on the console, try node preceding sudo ex. sudo node server.js

Here are the errors

 events.js:137 throw er; // Unhandled 'error' event ^ Error: listen EACCES 0.0.0.0:80 at Object._errnoException (util.js:1003:13) at _exceptionWithHostPort (util.js:1024:20) at Server.setupListenHandle [as _listen2] (net.js:1349:19) at listenInCluster (net.js:1407:12) at Server.listen (net.js:1495:7) at Object.<anonymous> (/home/abdus/Desktop/voice-recognition/test.js:7:4) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:573:32) at tryModuleLoad (module.js:513:12) 
0
source

Source: https://habr.com/ru/post/1501336/


All Articles