Sunday, 22 May 2011

Create Apache HTTPD Virtual Hosts

While you could edit your httpd.conf file and place all your Virtual Hosts there it is better to keep them organized.
You can have a directory for Virtual Hosts and a file for each Virtual Host.

Create vhost directory
I named the directory in which all Virtual Hosts will be stores “vhost”.
mkdir /etc/httpd/vhost

Instruct httpd.conf to load Virtual Hosts from “vhost”
vi /etc/httpd/conf/httpd.conf (and add theb code below at the bottom of it)
NameVirtualHost *:80
Include vhost/*.vh


Create a Virtual Host
vi /etc/httpd/vhost/example.com.vh (and add the code below)
<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    ServerAdmin webmaster@example.com
    DocumentRoot /usr/share/apache-tomcat-7.0.12/webapps/example.com
    ErrorLog logs/example.com-error_log
    CustomLog logs/example.com-access_log common

    <Directory "/usr/share/apache-tomcat-7.0.12/webapps/example.com">
        DirectoryIndex index.jsp
        Options FollowSymLinks
        AllowOverride All
    </Directory>

# Uncomment this if this if you want tu use mod_jk for this application
# JkMount /*.jsp ajp13
</VirtualHost>

Instead of /usr/share/apache-tomcat-7.0.12/webapps/ you could use /home/webapps or whatever you want for PHP.

Test the Virtual Host
service httpd restart
If the server doesn’t restarts without any errors, your syntax is good and the files exist. You can now test it in your browser.

No comments:

Post a Comment