Home Install Apache HTTPD on Docker
Post
Cancel
Preview Image

Install Apache HTTPD on Docker

This install assumes that Docker has been installed previously, and extends the Docker stack created for the Traefik Reverse Proxy.

The Apache HTTPD server project is an open-source HTTP server. In this case it is used to support this Jekyll document archive, by providing a full HTTP server to deliver the static pages generated by Jekyll.

Jekyll uses the source files in the Jekyll folder to build the static archive pages. The Jekyll files are then copied via SyncThing into a folder /Media/Archive_Jekyll/… on Titan where they reside alongside all the static data files and images /files/… served up in the archive. Apache serves both sets of files as required into a browser.

Install Apache HTTPD

Create folder for apache config data:

1
2
cd ~/docker
mkdir webserver

Add the following service definition to dc-webserver.yml in docker root folder

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
version: "3.9"

# NETWORKS ####################################################

networks:
  traefik_proxy:
    external: true

# VOLUMES #####################################################

volumes:
  titan_media_html:
    driver_opts:
      type: cifs
      o: "username=apache,password=[STRONGBOX],vers=3.0"
      device: "//192.168.0.10/Archive_Jekyll/jekyll_data/_site"

  titan_media_files:
    driver_opts:
      type: cifs
      o: "username=guest,password=,vers=3.0"
      device: "//192.168.0.10/Archive_Jekyll/files"

# SERVICES ####################################################

services:

  webserver:
    container_name: webserver
    image: httpd:latest
    #
    restart: unless-stopped
    #
    networks:
      - traefik_proxy
    #
    environment:
      TZ: $TZ
      PUID: $PUID
      PGID: $PGID
    #
    volumes:
      - titan_media_html:/usr/local/apache2/htdocs/
      - titan_media_files:/files/
      - $DOCKERDIR/webserver/my-httpd.conf:/usr/local/apache2/conf/httpd.conf
    #
    labels:
      - "traefik.enable=true"
      # HTTPS
      - "traefik.http.routers.webserver-secure.entrypoints=web_https"
      - "traefik.http.routers.webserver-secure.rule=Host(`$DOMAINNAME_CLOUD_SERVER`, `www.$DOMAINNAME_CLOUD_SERVER`)"
      - "traefik.http.routers.webserver-secure.tls=true"
      # Services
      - "traefik.http.routers.webserver-secure.service=webserver-svc"
      - "traefik.http.services.webserver-svc.loadbalancer.server.port=80"

From the Docker root folder, run this command to build the container:

1
sudo docker compose -f dc-webserver.yml up -d

Configure Apache HTTPD

The docker compose file creates two volumes linked to the folders on Titan/Media; one for the site’s HTML files (generated by Jekyll) and the other for the static data files (images/PDF/etc). This avoids all the static data files having to be copied from the Jekyll folder each time the site is built, and allows them to be any size.

NOTE: The site_html volume is currently not working due to permission issues.

It also maps a custom Apache config file into the internal container file location. To setup this config file, the default config file needs to be copied from the container just installed. Go to the Docker root folder and run:

1
sudo docker run --rm httpd cat /usr/local/apache2/conf/httpd.conf > ./webserver/my-httpd.conf

This puts a copy in the configuration folder created above. Edit this file; add a permitted directory, and an alias:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<Directory "/usr/local/apache2/htdocs">
 ...
</Directory>

# RCB: This is a mapping in Docker Compose file
# RCB: "Indexes" denied, so need full file path
<Directory "/files">        
    Options Indexes FollowSymLinks
#    Options FollowSymLinks  
    AllowOverride None
    Require all granted
</Directory>

...

<IfModule alias_module>
    # RCB: Followed this idea to allow static data files to be served
    # https://stackoverflow.com/questions/10363812/local-post-assets-with-jekyll
    Alias /files /files
</IfModule>

Copy HTML Files

I had hoped that Jekyll would create it’s static files into the _site folder mapped into the site_html folder on the NAS, but this led to permissions errors which I spent ages trying to fix unsuccessfully.

So I bottled out of that, and decided to use SynThing with one instance on the Mac with Jekyll (read-only), the other on TrueNAS to copy to /Media (write-only). The copy is fast enough that edits done on the Mac are rebuilt by Jekyll then copied to Titan in less than 10 seconds, and can then be served by Apache.

Resources

This post is licensed under CC BY 4.0 by the author.
Recently Updated
Trending Tags
Contents
Trending Tags