Skip to main content

Create Virtual Hosts and run multiple websites on Amazon server

You can create virtual hosts on any Linux or window platform if you are using Apache web server.
Virtual hosts or v-hosts is basically Apache feature. I’m considering
here Amazon server running with Apache version 2 or above. So, basically
for creating v-hosts you need to modify Apache’s configuration (httpd.conf) file. You need the root access for all this modifications. Here I’m showing how we create the “name-based virtual hosting“. This is the easiest way of creating virtual host.
On Amazon server httpd.conf is located on ‘/etc/httpd/conf/httpd.conf‘ location. You need to follow these steps:-

1. First, take the backup of this file so in case if anything goes wrong you can rollback changes.
2. Download this file in your local machine and open it in any text editor.
3. Go to section 3 (Virtual Hosts) of this document.

### Section 3: Virtual Hosts

4. Un-comment this line

NameVirtualHost *:80

5. Now create v-hosts like this

<VirtualHost *:80>
  ServerAdmin admin@mydomain1.com
  DocumentRoot /var/www/html/domainname1
  ServerName www.domainname1.com
  ErrorLog logs/www.domainname1.com-error_log
  CustomLog logs/www.domainname1.com-access_log common
</VirtualHost>
<VirtualHost *:80>
  ServerAdmin admin@mydomain2.com
  DocumentRoot /var/www/html/domainname2
  ServerName www.domainname2.com
  ErrorLog logs/www.domainname2.com-error_log
  CustomLog logs/www.domainname2.com-access_log common
</VirtualHost>

Here we have create two virtual host one www.domainname1.com and second one www.domainname2.com. We have specified 5 Apache directive into a VirtualHost container. We can put almost any Apache directive into a VirtualHost container. Let’s discuss each one by one.

ServerAdmin – Here we specified email address of server administrator. If there is any issue Apache show this email address for contact.
DocumentRoot – Here we give the absolute path of directory where our website files are located.
ServerName – Here we give the name of our domain which is pointed to “/var/www/html/domainname1″ directory.
ErrorLog – Absolute path of Error log file for this domain.
CustomLog – Absolute path of custom log file for this domain.

6. Restart the Apache web server to apply these changes.
You can restart your Apache server using Terminal or Putty on Windows.

service httpd restart

Note:- One more thing which you need to do is you
need to point both the domains “www.domainname1.com” and
“www.domainname2.com” to the IP address of the Amazon server.

The Apache server it self find out the domain name form request header and point the incoming request to correct “DocumentRoot” directory.

, , ,