Node.js: ECONNREFUSED on Port 80

后端 未结 5 728
暗喜
暗喜 2020-12-31 21:42

I\'ve written a web-server using Node.js. When I tried to test my server with the tester I\'ve written for it, I succeed only if the port I\'m using for the server is not 80

5条回答
  •  北海茫月
    2020-12-31 21:55

    You should not make a habit of running node as a privileged user. Here is a method I'm using on 6 different machines:

    Use iptables to forward incoming traffic on port 80 to 8080 like so:

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

    Then be sure to save that

    sudo iptables-save
    

    Youd also want to add that to rc.local so those are set at reboot or instance launch (in the case of EC2 or other cloud)

    Then you can safely start node listening on 8080 as any user.

提交回复
热议问题