Configure Virtual Hosting Link
There are different ways to set up Virtual Hosts, however we recommend the method below.
By default, Apache listens on all IP addresses available to it. We must configure it to listen only on addresses we specify. Even if you only have one IP, it is still a good idea to tell Apache what IP address to listen on in case you decide to add more.
Begin by modifying the NameVirtualHost entry in /etc/apache2/ports.conf so that the line reads:
File excerpt: /etc/apache2/ports.conf
Be sure to replace “184.108.40.206” with your Linode’s public IP address.
Now, modify the default site’s VirtualHost in the /etc/apache2/sites-available/default file so that the entry reads:
File excerpt: /etc/apache2/sites-available/default
Configure Virtual Hosts Link
You can create as many virtual hosting files as you need to support the domains that you want to host with your Linode. First, create a file in the /etc/apache2/sites-available/ directory for each virtual host that you want to set up. Name each file with the domain for which you want to provide virtual hosting. See the following example configurations for the hypothetical “ducklington.org” and “bucknell.net” domains.
CustomLog /srv/www/ducklington.org/logs/access.log combined
CustomLog /srv/www/bucknell.net/logs/access.log combined
Notes regarding this example configuration:
* All of the files for the sites that you host will be located in directories that exist underneath /srv/www You can symbolically link these directories into other locations if you need them to exist in other places.
* ErrorLog and CustomLog entries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), the logs directories must be created before you restart Apache.
Before you can use the above configuration you’ll need to create the specified directories. For the above configuration, you can do this with the following commands:
mkdir -p /srv/www/ducklington.org/public_html
mkdir -p /srv/www/ducklington.org/logs
mkdir -p /srv/www/bucknell.net/public_html
mkdir -p /srv/www/bucknell.net/logs
After you’ve set up your virtual hosts, issue the following commands:
This command symbolically links your virtual host file from sites-available to the sites-enabled directory. Finally, before you can access your sites you must reload Apache with the following command:
Should you ever need to disable a site, you can use the a2dissite command. For example, if you wanted to disable the duckington.org site, you would issue the following command:
The a2dissite command does the opposite of the a2ensite command.
Remember, after enabling, disabling, or modifying any part of your Apache configuration you will need to reload the Apache configuration again with the /etc/init.d/apache2 reload command.
Assuming that you have configured the DNS for your domain to point to your Linode’s IP address, Virtual hosting for your domain should now work.