Skip to main content
Version: 1.3.0

CDN

By default, Booklify serves all dynamic assets like book covers directly from the backend. This is fine for small to medium-sized instances, but is highly inefficient as the backend does not cache these assets. This means that every time a user requests a book cover, the backend has to fetch the image from the S3 bucket and serve it to the user. With large collections this can lead to a lot of unnecessary load on the backend.

One way to solve this is to serve these assets directly from the S3 bucket using nginx-s3-gateway.

A basic configuration for nginx-s3-gateway would look like this:

    cdn:
image: ghcr.io/nginxinc/nginx-s3-gateway/nginx-oss-s3-gateway:latest
ports:
- 8080:80
env_file: config/cdn.env

And the config/cdn.env file would look like this:

S3_BUCKET_NAME=booklify
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-access-key
S3_SERVER=s3.example.com
S3_SERVER_PORT=443
S3_SERVER_PROTO=https
S3_REGION=default
S3_STYLE=path
DEBUG=false
AWS_SIGS_VERSION=4
ALLOW_DIRECTORY_LIST=false
PROVIDE_INDEX_PAGE=false
APPEND_SLASH_FOR_POSSIBLE_DIRECTORY=true
PROXY_CACHE_MAX_SIZE=10g
PROXY_CACHE_INACTIVE=60m
PROXY_CACHE_VALID_OK=1h
PROXY_CACHE_VALID_NOTFOUND=1m
PROXY_CACHE_VALID_FORBIDDEN=30s

This configuration will serve all assets from the booklify S3 bucket on http://localhost:8080.

To use this in Booklify, you need to set the cdn_url setting.

{
"cdn_url": "http://localhost:8080"
}

This will make the Booklify frontend request all assets from the CDN instead of the backend.