Subject: Running multiple name-based websites on a single IP address
Author: Linux
In response to: Install Apache httpd on AWS EC2 instance
Posted on: 10/13/2011 08:59:31 PM
Your server has a single IP address, for example, 123.123.123.123, and multiple aliases (CNAMES) point to this machine in DNS. Specifically, You want to run a web server for www.example1.com and www.example2.com on the same machine.
example1.com --- DNS ---|
|
|--- 123.123.123.123 ---> /home/ec2-user
| + -- /example1.com
example2.com --- DNS ---| + -- /html
- -- index.html
+ -- /example2.com
+ -- /html
- -- index.html
Here is the corresponding settings in
"/etc/httpd/conf/httpd.conf"
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on IP addresse: 123.123.123.123
NameVirtualHost 123.123.123.123:80
<VirtualHost 123.123.123.123:80>
DocumentRoot /home/ec2-user/example1.com/html
ServerName example1.com
ServerAlias www.example1.com
# Other directives here
</VirtualHost>
<VirtualHost 123.123.123.123:80>
DocumentRoot /www/ec2-user/example2.com/html
ServerName example2.com
ServerAlias www.example2.com
# Other directives here
</VirtualHost>
>
> On 10/13/2011 06:58:40 PM
Linux wrote:
So now we have:
A basic Linux box running in the cloud;
A public static ipAddress binding to the instance/box;
A public domain pointing to the ipAddress and hence the box;
A Tomcat container running in the box;
Now we want an extra Apache web server sitting in front of Tomcat. Why? The advantages are:
Apache is efficient in handling static contents via caching mechanism.
Apache supports multiple domains on the same ipAddress via VirtualHost
Better security by hiding Tomcat
AWS micro EC2 instance supports the yum package manager, which installs RPM packages from a repository.
# yum install httpd
The main stuff is loaded under /etc/httpd
Before starting our server, we can configure parameters in Apaches "/etc/httpd/conf/httpd.conf". For example, the default document root is:
DocumentRoot /var/www/html
You may want to change it into:
DocumentRoot /home/ec2-user/public_html
Lets create a HTML file named "test.html" in public_html directory:
<html>
<body>
<p>Apache httpd server is running on AWS EC2 instance!</p>
</body>
</html>
Now it's time to start the server:
# /etc/init.d/httpd start
If you want your server to survive box reboot:
# chkconfig httpd on
References: