Apache Virtual Hosts on Ubuntu 16.04

Apache Virtual Hosts on Ubuntu 16.04

Apache Virtual Hosts on Ubuntu 16.04


Subdomain aanmaken DNS provider

Onder ondertitel

, Apr 21, 2016

Maak een sub-domain

Creating the sub-domain is a CNAME record - setting it up is much like the A record, but instead of the @ as the hostname, we put the subdomain we want - for example; blog as the hostname will equate to blog.example.com.

Maak een Apache Virtual Host

A Virtual Host is - in it's simplest form - configuration for a host -- your sub-domain.

You're going to want to access your server via SSH - PuTTy is an excellent program, however Digital Ocean offer a browser-based solution - use what's best for you.

(Assuming you have Apache installed already)

When using Apache 2 the .conf file should be in /etc/apache2/sites-available/.

Now update your Apache2 configuration.

We maken een bestand met de naam tower-pattern.conf met daarin:

<VirtualHost *:80>
    ServerName tower-pattern.anormapart.com
    DocumentRoot /var/www/tower-pattern.anormapart.com/
    ServerAdmin jef.inghelbrecht@inantwerpen.com
    <Directory /var/www/tower-pattern.anormapart.com>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all

Je moet het subdomein nu enablen:

sudo a2ensite tower-patern.conf

Op deze site staat het anders: Enable the site in apache with:

sudo a2ensite sub.yourdomain.com

(or whatever you named your site in the config)

Je kan die weer disablen met:

sudo a2dissite tower-patern.conf

Sla dit bestand op in de sites-available map. De extensie moet conf zijn!

Now create /var/www/tower-pattern.anormapart.com and restart Apache2:

mkdir -p /var/www/towerpattern.anormapart.com
sudo service apache2 restart

Om .htaccess te laten werken in een submap

In de <Directory> section van zowel apache2.conf als van de tower-pattern.conf moet je toestemming om de instellingen van de Apache server te kunnen overschrijven:


<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted


    <Directory /var/www/tower-pattern.anormapart.com>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all

CORS on Apache

To add the CORS authorization to the header using Apache, simply add the following line inside either the <Directory>, <Location>, <Files> or <VirtualHost> sections of your server config (usually located in a *.conf file, such as httpd.conf or apache.conf), or within a .htaccess file:

Header set Access-Control-Allow-Origin "*"

To ensure that your changes are correct, it is strongly reccomended that you use

apachectl -t

to check your configuration changes for errors. After this passes, you may need to reload Apache to make sure your changes are applied by running the command sudo service apache2 reload


apachectl -k graceful

.Altering headers requires the use of mod_headers. Mod_headers is enabled by default in Apache, however, you may want to ensure it's enabled by run

a2enmod headers

Note: you can also use add rather than set, but be aware that add can add the header multiple times, so it's likely safer to use set.

2017-04-26 00:56:24