How do I run Node.js on port 80?

Best way redirecting the port 3000 to port 80
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

It is currently not recommended to run node on port 80, as that requires running node as root.
How attached are you to apache? Proxying node through nginx is a tried and true solution, with an nginx-config such as this:
Nginx documentation:
upstream node_cluster {
    ip_hash;   
    server 127.0.0.1:8000;
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
}

server {
    listen 0.0.0.0:80;
    server_name foo;
    access_log /var/log/nginx/foo.log;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;

      proxy_pass http://node_cluster/;
      proxy_redirect off;
    }
}

0 pensamientos:

Post a Comment

feedback!