有三种方法:
1:通过sudo。因为系统默认非root用户,不能使用1024以及小于它的端口
2: 通过iptables重定向到别的端口:
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
3: 给一个普通用户,有想root用户一样使用sockets的能力。
sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep /usr/bin/nodejs
我的系统是ubuntu14.04,nodejs 为0.10.37
参考链接:
1: http://stackoverflow.com/questions/23281895/node-js-eacces-error-when-listening-on-http-80-port-permission-denied
2:http://serverfault.com/questions/602240/how-to-run-node-js-app-on-port-80-are-processes-blocking-my-port