How to deploy audiobookshelf

Recently, I watched 3 body problem TV series made by Tencent. However, it only finished first of three parts of original book. But I want to see more. I did not like reading so I decide to listen to audiobooks. Here I record how to deploy Audiobookshelf with apache2.

How to install Audiobookshelf using docker compose

Log into your server as root

1
2
3
mkdir audiobookshelf
cd audiobookshelf/
vim docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
services:
audiobookshelf:
image: ghcr.io/advplyr/audiobookshelf:latest
ports:
- "127.0.0.1:13378:80"
volumes:
- /srv/downloads/audiobookshelf:/audiobooks
- ./podcasts:/podcasts
- ./config:/config
- ./metadata:/metadata
environment:
- TZ=Europe/Stockholm
1
docker compose up -d

Configure apache2

1
vim /etc/apache2/sites-available/audio.example.com.conf 
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
<VirtualHost *:80>
ServerName audio.example.com

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
ServerName audio.example.com

SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/audio.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/audio.example.com/privkey.pem

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:13378/
ProxyPassReverse / http://127.0.0.1:13378/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://127.0.0.1:13378/$1" [P,L]

# Set the maximum allowed size for the client request body
LimitRequestBody 1024000000

# Headers to pass to the backend server
#RequestHeader set Host $host
RequestHeader set X-Real-IP $remote_addr
RequestHeader set X-Forwarded-For $proxy_add_x_forwarded_for
RequestHeader set REMOTE-HOST $remote_addr
RequestHeader set X-Forwarded-Proto https

</VirtualHost>
1
2
3
a2ensite audio.example.com.conf
service apache2 restart
certbot --apache -d audio.example.com

Reference

  1. https://www.audiobookshelf.org/docs/
  2. https://github.com/advplyr/audiobookshelf/issues/241