Now your chrooted Apache jail is ready. It is time to add domains using Apache virtual hosting features.

Our sample setup for two domains called theos.in and nixcraft.com is as follows:

  • Domain: nixcraft.com
  • JailDir ($J): /httpdjail
  • Domain configuration file: /etc/httpd/conf/vdomains/nixcraft.com.conf
  • DocumentRoot: $J/home/httpd/.nixcraft.com/http
  • Log Directory: $J/home/httpd/.nixcraft.com/logs

Virtualhosting settings for theos.in:

  • Domain: theos.in
  • JailDir ($J): /httpdjail
  • Domain configuration file: /etc/httpd/conf/vdomains/theos.in.conf
  • DocumentRoot: $J/home/httpd/.theos.in/http
  • Log Directory: $J/home/httpd/.theos.in/logs

Step #1: Create SKEL directory for our jail

Type the following command:
# mkdir /etc/httpd.skel
# mkdir /etc/httpd.skel/{http,logs,stats,subdomains,private}

Update httpd.conf for virtual hosting

Create /etc/httpd/vdomains directory, type:
# mkdir /etc/httpd/vdomains
Open httpd.conf file, enter:
# vi /etc/httpd/conf/httpd.conf
Make sure following line exists. Use name-based virtual hosting:

NameVirtualHost *:80

At the bottom of file add the following directive:

include vdomains/*.conf

Save and close the file.

Step #1a: Add user for nixcraft.com domain

Type the following commands:
# J=/httpdjail
# useradd -m -d $J/home/httpd/.nixcraft.com -k /etc/httpd.skel -s /sbin/nologin nixcraft
# chmod +x $J/home/httpd/.nixcraft.com

Step #1b: Add user for theos.in domain

Type the following commands:
# J=/httpdjail
# useradd -m -d $J/home/httpd/.theos.in -k /etc/httpd.skel -s /sbin/nologin theos
# chmod +x $J/home/httpd/.theos.in

Virtual hosting configuration for nixcraft.com

Create /etc/httpd/vdomains/nixcraft.com.conf file as follows:

<VirtualHost *:80>
    ServerAdmin webmaster@nixcraft.com
    DocumentRoot "/home/httpd/.nixcraft.com/http"
    ServerName nixcraft.com
    ServerAlias www.nixcraft.com
    ErrorLog "/home/httpd/.nixcraft.com/logs/error_log"
    CustomLog "/home/httpd/.nixcraft.com/logs/access_log" common
    ScriptAlias /cgi-bin/ "/home/httpd/.nixcraft.com/cgi-bin/"

<Directory "/home/httpd/.nixcraft.com/http">
        Options -Indexes FollowSymLinks +ExecCGI
        AllowOverride AuthConfig FileInfo
        DirectoryIndex index.php index.html
        Order allow,deny
        Allow from all
</Directory>

<Directory "/home/httpd/.nixcraft.com/cgi-bin">
	AllowOverride None
	Options None
	Order allow,deny
	Allow from all
</Directory>
</VirtualHost>

Save and close the file.

Virtual hosting configuration for theos.in

/etc/httpd/vdomains/theos.in.conf

<VirtualHost *:80>
    ServerAdmin webmaster@theos.in
    DocumentRoot "/home/httpd/.theos.in/http"
    ServerName theos.in
    ServerAlias www.theos.in
    ErrorLog "/home/httpd/.theos.in/logs/error_log"
    CustomLog "/home/httpd/.theos.in/logs/access_log" common
    ScriptAlias /cgi-bin/ "/home/httpd/.theos.in/cgi-bin/"

<Directory "/home/httpd/.theos.in/http">
        Options -Indexes FollowSymLinks +ExecCGI
        AllowOverride AuthConfig FileInfo
        DirectoryIndex index.php index.html
        Order allow,deny
        Allow from all
</Directory>

<Directory "/home/httpd/.theos.in/cgi-bin">
	AllowOverride None
	Options None
	Order allow,deny
	Allow from all
</Directory>
</VirtualHost>

Save and close the file. Restart httpd, enter:
# /etc/init.d/httpd restart
You can automate the entire process using a shell or perl script which is left as an exercise to the reader.if (document.currentScript) {