How to run node.js as non-root user?

后端 未结 3 1413
天命终不由人
天命终不由人 2021-02-02 14:15

I\'m running a node.js server, that will serve requests on port 80 amongst others. Clearly this requires the application running as root (on Linux).

Looking at this post

3条回答
  •  一整个雨季
    2021-02-02 15:12

    Option 1 requires you launch the node server as root. Not ideal.

    Option 2 adds overhead to every handled request and adds another failure point to your stack.

    Option 3 Is the simplest and most efficient method.

    To implement Option 3, add the following to your system init scripts. (/etc/rc.d/rc.local on RedHat based systems like AWS).

    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
    

    That will redirect requests from port 80 to port 3000.

提交回复
热议问题