Need a web scraping or data wrangling solution? Check out my resume (PDF).
John Bokma's Hacking & Hiking

How to Alias a file in Apache

February 28, 2019

In the early evening I wanted to configure the Apache webserver I run on Ubuntu in a virtual machine to host a local version of this website. Because currently my personal website is split in an old part and a new part residing in different directories I had to use the Alias directive to map my new blog under the older part of this site:

    Alias "/blog/" \
          "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/blog/"
    <Directory "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/blog">
        Require all granted
    </Directory>

This worked perfectly. Note how a backslash is used to split a long line in two. Apache supports this method of breaking up into multiple lines. However, make sure no space, or any other character, follows the backslash.

Next, because my new blog has its own style sheet (CSS), I had to alias a single file. With just the alias:

    Alias "/style5.css" \
          "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/style5.css"

It didn't work; my new blog had no styling and accessing the CSS file directly in the browser resulted in the following message:

Forbidden

You don't have permission to access /style5.css on this server.

Apache/2.4.18 (Ubuntu) Server at lc.johnbokma.com Port 80

I checked the error log of the virtual host. I use per virtual host log files to make life easier. It had several entries like this one:

[Thu Feb 28 16:59:30.421445 2019] [authz_core:error] [pid 23604] [client 192.168
.11.108:56288] AH01630: client denied by server configuration: /home/john/Amber/
in-house/sites/johnbokma.com/site/htdocs/style5.css

Googling on "client denied by server configuration" (without the quotes) gave as first result a page in the Apache wiki aptly named Client denied by server configuration. From this I learned that I also had to provide the Directory directive to allow access to the single file. This part of the configuration became as follows:

    Alias "/style5.css" \
          "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/style5.css"
    <Directory "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/">
        Require all granted
    </Directory>

When I refreshed the browser my new blog had now style associated with it; the permission issue had been fixed.

For completeness sake I have included the full configuration for my local website below. Note that I also have a cgi-bin directory and the virtual host has its own access and error logs.

<VirtualHost *:80>
    ServerName lc.johnbokma.com
    DocumentRoot /home/john/Amber/in-house/sites/johnbokma.com-old/site/web

    <Directory "/home/john/Amber/in-house/sites/johnbokma.com-old/site/web">
        Require all granted
    </Directory>

    Alias "/blog/" \
          "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/blog/"
    <Directory "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/blog">
        Require all granted
    </Directory>

    Alias "/style5.css" \
          "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/style5.css"
    <Directory "/home/john/Amber/in-house/sites/johnbokma.com/site/htdocs/">
        Require all granted
    </Directory>

    ScriptAlias "/cgi-bin/" \
                "/home/john/Amber/in-house/sites/johnbokma.com-old/site/cgi/"

    <Directory "/home/john/Amber/in-house/sites/johnbokma.com-old/site/cgi">
        Options +ExecCGI -MultiViews
        AddHandler cgi-script .cgi
        Require all granted
        AllowOverride None
    </Directory>

    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/lc-johnbokma-com-error.log
    CustomLog ${APACHE_LOG_DIR}/lc-johnbokma-com-access.log combined
</VirtualHost>

Related