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/ (and add the code below)
<VirtualHost *:80>
    DocumentRoot /usr/share/apache-tomcat-7.0.12/webapps/
    ErrorLog logs/
    CustomLog logs/ common

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

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

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