Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run more than one app on one instance of EC2

I have a couple of small production sites and a bunch of fun hobbyist/experimental apps and such. I'd like to run all of them on one EC2 instance.

Can I install node.js, npm, express and couchdb once, and then run each app on a different port, and adjust the dns settings at my domain registry to point to the appropriate place?

Update: Thanks Mike! For anyone else who's looking for multiple IP addresses on EC2: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html

like image 987
Costa Michailidis Avatar asked May 14 '13 17:05

Costa Michailidis


People also ask

Can we deploy multiple applications in EC2 instance?

You cannot deploy multiple applications on the same instance.

Can a server run more than one application?

To run multiple applications on the same server Obtain a separate subdomain for each app and map the subdomains to the application server's or load balancer's IP address. Edit each app's configuration to specify the appropriate subdomain.

How many requests can one EC2 instance handle?

In its steady state, the site must handle 1,000 concurrent visitors at any given time. Visitors spend on average 30 seconds on each page before they click on a different link or leave the site.


1 Answers

There are multiple ways to go about it.

Different Ports

You could run each Node.js process on a different port and simply open the ports to the world. However, your URLs would need a port on the end of the hostname for each project. yoururl.com:8080/ would technically work, but probably not what you're looking for.

Multiple IP Addresses

You could use multiple IP addresses on one EC2 instance, however, they come with an additional cost of about $3.65 a month each. So if you have 10 different domains you want to host on once instance then that's over $30 a month extra in hosting fees.

On the flip side, any domain using SSL needs it's own IP address.

Also, there are limits to the number of IP addresses you can assign to an instance and the smaller the instance, the less IP addresses you get.

The number of IP addresses that you can assign varies by instance type. Small instances can accommodate up to 8 IP addresses (across 2 elastic network interfaces) whereas High-Memory Quadruple Extra Large and Cluster Computer Eight Extra Large instances can be assigned up to 240 IP addresses (across 8 elastic network interfaces). For more information about IP address and elastic network interface limits, go to Instance Families and Types in the Amazon EC2 User Guide.

Express Vhosts

Express comes with virtual host functionality. You can run multiple domains under one Node.js/Express server and setup routes based on domain name. vhost under Express enables this.

Reverse Proxy

You can setup Nginx in front of multiple application servers. This has the most flexibility. You can have one Node.js process per domain which allows you to do updates and restarts on one domain at a time. It also allows you to host applications servers such as Apache/PHP under the same EC2 instance along side your Node.js process.

With Nginx acting as a reverse proxy you could also host different application servers under the same domain, but serving different paths.

For instance, Node.js could serve the main root path of a domain but you could setup the /blog/ path to go to a Apache/PHP/Wordpress setup on the same EC2 instance.

like image 122
Daniel Avatar answered Oct 20 '22 21:10

Daniel