It's probably related to this question: How to run more than one app on one instance of EC2
But that question only seemed to be talking about multiple node.js apps.
I am trying learn several different things, so I'm building different websites to learn Ruby on Rails, LAMP, and node.js. Along with my personal website and blog.
Is there any way to run all these on the same EC2 instance?
First, there's nothing EC2-specific about setting up multiple web apps on one box. You'll want to use nginx (or Apache) in "reverse proxy" mode. This way, the web server listens on port 80 (and 443), and your apps run on various other ports. Each incoming request reads the "Host" header to map the request to a backend. So different DNS names/domains show different content.
Here is how to setup nginx in reverse proxy mode: http://www.cyberciti.biz/tips/using-nginx-as-reverse-proxy.html
For each "back-end" app, you'll want to:
1) Allocate a port (3000 in this example)
2) write an
upstream
stanza that tells it where your app is3) write a (virtual)
server
stanza that maps from the server name to the upstream locationFor example:
I prefer to have Nginx in front of Apache for two reasons: 1) nginx can serve static files with much less memory, and 2) nginx buffers data to/from the client, so people on slow internet connections don't clog your back-ends.
When testing your config, use
nginx -s reload
to reload the config, andcurl -v -H "Host: app1.example.com" http://localhost/
to test a specific domain from your configAdding to the @Brave answer, I would like to mention the configuration of my nginx for those who are looking for the exact syntax in implementing it.
Just create two server objects with unique server name and the port address.
Mind proxy_pass in each object.
Thank you.