Creating a Virtual Web Host

From Gruff Goat Wiki
Jump to: navigation, search

Create a Virtual Site

Create directories

If this is a new site then

 cp -R /home/sites/skel /home/sites/sitenum
 ln -s /home/sites/sitenum /home/sites/

Create user and group

 pw group add sitenum
   Username= username
   Fullname= fullname
   Login group=
   Invite groups= sitenum
   Login class=
   Shell= nologin
   Home directory= /home/sites/sitenum
   Use password= yes
   Empty password= no
   Random password= yes
   Lock account= no

Change file ownership and group

 chown -R username /home/sites/sitenum
 chgrp -R sitenum /home/sites/sitenum

Add FTP user for site

Use PureFTPd and PureDB for FTP server and virtual users. PureFTPd website

My PureFTPd pages

 pure-pw useradd username -u username -g sitenum -d /home/sites/sitenum
 pure-pw mkdb

Apache virtual site

Virtual site configurations are stored in the a separate file, such as


Each site needs a line added to the end of the httpd.conf.

 echo 'Include etc/apache2/virt/sitenum' >> /usr/local/etc/apache2/httpd.conf

This is a typical virtual site configuration

 <Directory /home/sites/sitenum/web>
   Order allow,deny
   Allow from all
 <Directory /home/sites/sitenum/web/usrbin>
   Options +ExecCGI
   DocumentRoot /home/sites/sitenum/web
   ErrorDocument 401 /error/401-authorization.html
   ErrorDocument 403 /error/403-forbidden.html
   ErrorDocument 404 /error/404-file-not-found.html
   ErrorDocument 500 /error/500-internal-server-error.html
   RewriteEngine on
   RewriteCond %{HTTP_HOST}                !^$
   RewriteCond %{HTTP_HOST}                !^$ [NC]
   RewriteRule ^/(.*)            $1 [L,R]
   RewriteOptions inherit
   # BEGIN WebScripting SECTION.
   #AddHandler cgi-wrapper .cgi
   #AddHandler cgi-wrapper .pl
   #AddHandler cgi-script .cgi .pl
   # END WebScripting SECTION.

Reload Apache

 /usr/local/etc/rc.d/ reload

Password Protect Directories


To protect a specific web directory, you must either set the appopriate directives in an .htaccess file or in the <Directory> section of the configuration files. I prefer to make the setting in the each virtual host configuration file. Either way, the directives are same.

For more detailed information on htaccess, please see the following:

User-Level Protection


Do not place you password file in your web document tree. Also create it as a hidden file and change the permissions on the file. The file iteself may be named anything you wish, though it is common to call it .htpasswd. If your web documents exist in ~/web then:

 htpasswd -c ~/access/.htpasswd username  # Creates a new file
 htpasswd ~/access/.htpasswd username     # Adds or modifies the user in the current file
 # Each of these command will require you to enter the password twice

Change the permissions on the file to make it more secure.

 chown siteowner:webserver ~/access/.htpasswd
 chmod 640 ~/access/.htpasswd