30/11/2020

Apache Vhost

Apache Vhost

1. First create a directory where all the vhost will be stored (mine will be in /etc/httpd/sites

mkdir /etc/httpd/sites

2. Create a new file with servername.conf using:

vim /etc/httpd/sites/servername.conf

3. Usually it should have following content:

  1. <VirtualHost *:80>
  2.             ServerName example.com
  3.             ServerAlias www.example.com
  4.             DocumentRoot /path/to/website/directory
  5.             ErrorLog /path/to/error/log
  6.             CustomLog /path/to/access/log
  7.             <Directory /path/to/website/directory>
  8.               AllowOverride None
  9.              DirectoryIndex index.html index.php
  10.              Require all granted
  11.             </Directory>
  12. </VirtualHost>
  1. It is the opening block for the vhost and it listens on port 80 (can also be 443 or 8080 depending on the application)
  2. It will be the servername which is usually the domain name of the website
  3. Another name which will point to the same website and same documentroot. Common examples is www.example.com
  4. Where your website files is stored
  5. Where error log will be stored
  6. Where access log will be stored
  7. Start of directory block where information about the directory is found
  8. Option to either allow all access to website or allow access to only authenticated users using .htpasswd and .htaccess
  9. Specifies which file will be displayed on eterring the website (usually index.html or index.php)
  10. Access control
  11. Closing of directory block
  12. Closing of Vhost block

4. The following line should then be addeed so that Apache can load the vhosts:

IncludeOptional relative/path/to/file/*.conf
It will load all files with extension .conf found int the directory specified.

Leave a Reply

Your email address will not be published.