Skip to main content

Configuring VirtualHost Domains in Apache on Raspberry Pi

We will be paying most attention to Name-based Virtual Sub-domain Support using a single IP address, since that is the configuration we are building, here, and therefore of the greatest interest to us…

Here we are configuring hosting of multiple Virtual hostnames on a single Apache server install using the *.conf files found in the /etc/apache2/sites-available and /etc/apache2/sites-enabled directories installed by default when using the Debian apt software package system.

The Apache Project provides documentation and examples for this:


In studying the documentation and examples provided by Apache we find that the VirtualHost directives have a couple key features in creating the sub-domain mappings for the IP address. Specifically:

  • The IP address selector line should be written using wildcard IP addresses.
  • the ServerName directive, is not required per se, but failing to use it correctly in the VirtualHost definition may yeild unexpected results.

Following is an example of a common VirtualHosts configuration taken directly from the Apache project's documentation:

      # Ensure that Apache listens on port 80
      Listen 80
      <VirtualHost *:80>
          DocumentRoot "/www/example1"
          ServerName www.example.com

          # Other directives here
      </VirtualHost>

      <VirtualHost *:80>
          DocumentRoot "/www/example2"
          ServerName www.example.org

          # Other directives here
      </VirtualHost>
  

The default .conf file provided by the Debian apt install of Apache looks like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Note that there is no ServerName directive definition within the default coniguration file provided by the apt package.

What's next?

first off we need to add a sub-domain definition to the virtualhost definition(s) in the .conf file — the .conf files found in /etc/apache2//sites-available are Apache Web Server Configuration files

Our goal here is to create a virtual subdomain on the Raspi 3b+ webserver such that a WordPress installation at /var/www/wordpress will show up at http://wordpress.raspberrypi.local/

There exists a file on this host named /etc/apache2/sites-enabled/wordpress.conf — we reproduce that file, below.

<VirtualHost *:80>
    DocumentRoot /srv/www/wordpress
    <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /srv/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>
  

Here again we see no definition for ServerName — does this mean there can be no forwarding of wordpress.raspberrypi.local from this server?

Comments

Popular posts from this blog

Installing Signal on the Raspberry Pi

Linux (Debian-based) Install Instructions The following instructions for installing the Signal client on Linux are copied verbatim from signal.org . These instructions are formatted so they may be used directly as a bash shell script. # NOTE: These instructions only work for 64-bit Debian-based # Linux distributions such as Ubuntu, Mint etc. # 1. Install our official public software signing key: wget -O- https://updates.signal.org/desktop/apt/keys.asc \ | gpg --dearmor > signal-desktop-keyring.gpg cat signal-desktop-keyring.gpg \ | sudo tee /usr/share/keyrings/signal-desktop-keyring.gpg > /dev/null # 2. Add our repository to your list of repositories: echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/signal-desktop-keyring.gpg]\ https://updates.signal.org/desktop/apt xenial main' \ | sudo tee /etc/apt/sources.list.d/signal-xenial.list # 3. Update your package database and install Signal: sudo apt update && sudo apt install signal-desktop ...

CSS Animation and Movement Effects

List of documentation with examples from w3schools.com: CSS 3 transition Property The transition property is a shorthand property for: transition-property transition-duration transition-timing-function transition-delay Note:  Always specify the transition-duration property, otherwise the duration is 0s , and the transition will have no effect. CSS Animations tutorial from W3 Schools

Real-time Digital Clocks

Links to source code for real-time digital clocks in Javascript: W3 Schools TryIt ™ Javascript Clock How to Design Digital Clock using JavaScript ? Some clocks made by sumkittehz using the examples listed above: codez: Real-time Digital Clocks codez: Clock 2 codez: Digital-Clock-js