Virtual Host
Here is an example for Apache to listen to any ip from port 80 for the name wiki.yourdomain.com
. wiki.yourdomain.com
could be something your type in to your web browser. The root directory of this virtual host is /var/www/YOURSITE
.
<VirtualHost *:80> DocumentRoot "/var/www/YOURSITE" ServerName wiki.yourdomain.com <Directory "/var/www/YOURSITE"> allow from all Options None Require all granted </Directory> </VirtualHost>
Add this code into your apache.conf file, or for some OS, save this code under /etc/apache2/sites-enabled/any_name_you_like.conf, and then restart the apache server.
To test if this is working:
- Apache server should be able to restart without any problem. (If error, try
systemctl status apache2.service
in Ubuntu) - Put an index.html file in the directory /var/www/YOURSITE. Make sure your Apache server has access right to it (
sudo chown -R www-date:www-data /var/www/YOURSITE
in Ubuntu 16.04) - Use a web browser; type the url, and you should be able to access your index.html
Additional Fun
- You can do mod rewrite in virtual host (redirect to https, for example)
- You can do virtual host on port 443, and set up the cert needed inside a virtual host.