开发者

Configuring Ubuntu Server so Node.Js app (port 3000) is served at a particular domain server address

开发者 https://www.devze.com 2023-03-05 18:25 出处:网络
I\'ve built开发者_如何学C a node.js-express app.By default it is listening on port 3000.I have the system hosted on an EC2 instance and have pointed a domain\'s A record to the AWS elastic IP address.

I've built开发者_如何学C a node.js-express app. By default it is listening on port 3000. I have the system hosted on an EC2 instance and have pointed a domain's A record to the AWS elastic IP address.

I'd like for HTTP requests to the domain name to automatically be directed to port:3000 or I'd like to be able to start the Express HTTP server up on port 80. (I tried starting up the node http server on port 80 but got an error)

I can access the node app if I type www.myurl.com:3000 but I need to be able to drop that requirement for the good of the end users.

Does anyone know how to make node and ports and domains all play nicely together on my amazon-buntu server?


I found this article helpful when I had that same problem:

http://www.debian-administration.org/articles/386

I ended up using authbind -- once configured you just do:

authbind node myscript


In my deployment script, I usually just run this to ensure TCP traffic on port 80 goes to 3000:

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000


You have problem that same with me on several month ago. I have NodeJS application http://obrool.com (Chats application) and http://wpfight.com (Realtime Flight Simulator) that running on Amazon EC2 Small. I run this website over 3 month without any restart which it's mean stable for production.

I use Express & Nowjs running on port 8003. Then I use Haproxy as front-end to redirect port 80 into port 8003. So, if you have express listening on port 3000, with Haproxy, you can make it running on express.your-domain.com (port 80).

Here are my tutorial running NodeJS application on port 80 in Amazon EC2 Ubuntu :

http://www.yodi.me/blog/2011/09/20/run-nodejs-and-nowjs-as-sub-domain-in-port-80-using-haproxy-websocket-ubuntu/

PS, i already use many method :

  1. Using NGINX for reverse proxy I hack my NGINX 0.8 with TCP Upstream but failed because it’s still not supporting web sockets. Based on https://github.com/LearnBoost/socket.io/wiki/Nginx-and-Socket.io It’s said use NGINX 1.1.1 for has support for proxying HTTP/1.1. I use latest NGINX 1.1.3 and it’s doesn’t works. Even @NGINX reply my tweets and said there no web-socket support yet.

  2. Node-http-proxy still has issues.

  3. Authbind and sudo You can do authbind to make nowjs run on port 80 or installing as sudo. Some times it's come with problem.

  4. IPTABLES sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8003 Better you use runit to make nodejs run as service and on user permission.

  5. HAProxy on Websocket Socket.io doing several error and handshake to get user connected. It probably take around 5-10s.

0

精彩评论

暂无评论...
验证码 换一张
取 消