-1

I have an EC2 instance running Ubuntu 12.04. I've got nodejs and mongo installed. This instance also has an IP address allocated to it.

I'd like to have my application (a nodejs app) running from a directory (let's say /var/www/node/my_app) connected to a local mongo db (I've installed the db manually and its not from Amazon marketplace, however this is for development/tests purposes so at the moment performance is not an issue). I'd like then to have a domain linked with the ip address (this was done through my domain provider and is ready) in turn linked to my app (running from /var/www/node/my_app) so when I go to www.mydomain.com I'll see my app running on my web browser.

I'd also like to be able to have a different app running from /var/www/node/my_app2 that could be accessed through another domain or a subdomain (app2.mydomain.com for instance).

I can do all that very easily using PHP/MySQL/Webmin/Apache. All I need to do is have my application on a particular folder and have webmin to manage/create virtual hosts pointing a particular domian/subdomain to it.

My question is: can someone, explain to me, step by step (or point me to a tutorial/site/documentation) how I can have the same setup using node? I understand it'll probably means installing other pieces of software (something like nginx for instance)?

Background: I have read many tutorials on how to start with node in which they explain how to install node on your local machine, create a server to listen to a port (something like 8080) and if I visit http://localhost:8080 on my local computer it works (Yes, I've tried and it does work) however I cannot replicate the same on my EC2. Not to mention that I'd rather not use www.mydomain.com:8080 (for instance) and would prefer to have the ability to run more than one app from the same domain (using subdomains).

Can anyone help?

Many thanks

WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
  • The question is too broad. You are asking someone to do googling for you, while you can do it yourself. Do not expect to find answers straight away but be patient and keep working to understand how things work, relate and how to move forward. – moka Sep 13 '13 at 13:32
  • Run new instance, run `yum update -y`, then just follow official guides with mongodb installing as a service and node.js (normal installation on Linux). Then install express.js and mongodb using npm (`npm install`), and follow first examples of express.js. There is no way of mistakes here. The tutorials and guides online on official sources are well documented and cover any possible scenarios. Setting up node.js on EC2, google has about 5 articles and tutorials on first page. It is normal to face issues - just be able to understand them and approach for a fix. – moka Sep 13 '13 at 15:49
  • No, I do not want anyone to do any googling for me. My main question is whether this approach is actually achievable with this setup. I haven't found a single tutorial that explains in details how to run multiple apps/sites (with different domains) from a single node box. I cannot see how the question is too broad as I have a very specific set of requirements and I want to know whether that's possible or not. – WagnerMatosUK Sep 13 '13 at 15:52
  • For multiple domains, use nginx as proxy. Bear in mind that it will lead to complexities (need of downloading and recompiling) regarding proxying websockets traffic, but will work for most needs. Or use any of popular node.js proxy management modules for proxying traffic to different processes based on domain name. – moka Sep 13 '13 at 15:54

2 Answers2

2

This is a setup for a Linux VM where I run a MEAN app.

  • I run my node application on a non-privileged port (>= 1024) on my VM. I use an Upstart/Monit combo to start it and keep it running. You can check out this blog post about how to set it up.

  • For the port 80 traffic I use NGINX as a reverse proxy to my node aplication. NGINX will allow you to route the incoming traffic based on the incoming URL. Here is link to a good SO page on how to set that part up.

Community
  • 1
  • 1
Jason Sich
  • 148
  • 2
  • 7
1

Consider using http-proxy: http://blog.nodejitsu.com/http-proxy-intro

Or nginx for proxying based on domain names.

moka
  • 22,846
  • 4
  • 51
  • 67
  • The above did help me move towards what I have mind, however it is not yet the solution I wanted. Maybe what I want it is not yet available. One thing I do not understand is that while on terminal, if I run my app (including the reverse proxy one) with node myapp.js it will run. However once I leave the terminal, the app stops running. How do I get around that? – WagnerMatosUK Sep 14 '13 at 16:28
  • Use `screen` or services to run node as background process. – moka Sep 14 '13 at 17:21