This is merely a documentation of my specific setup, i.e. what I found works for me.
You might have entirely different requirements and expectations of security, etc.
Always use your Brain™
Always read up on up-to-date documentation and current best practices.
Inform yourself, research, and treat my documentation as what it truly is: a mere info-dump.
This section has been heavily inspired by Micheal Jack’s nextcloud-quadlet repository!
I simply adapted his proceeding to my needs, by changing some paths, using my monolithic caddy instance for reverse proxying, etc.
Caddy within Caddy?
Note that, similar to the original author (see above), I use two Caddy instances.
One to serve Nextcloud itself and another one in front of it for reverse proxying.
The only difference between my and the original author’s approach is that my instance, responsible for reverse proxying, is not part of the Nextcloud pod.
Prerequisites
Make sure you have podman installed and a frontendCaddy instance set up.
First, we tell the Caddy instance within the pod (which I’ll refer to as the backend instance), how to serve the Nextcloud by creating the necessary Caddyfile within ~/containers/nextcloud/caddy/config:
for the hostname equal to the name specified for its container
within the Nextcloud pod, or more specifically within it’s specified Network.
The pod configuration will take care of forwarding an actual outside/system port to this pod-internal one.
Frontend Caddyfile
As mentioned, the external caddy instance (which I will refer to as the frontend instance) is used for reverse proxying. Note that the backend caddy instance expects incoming traffic on port 8080, as specified in its container config.
Therefore, we simply add a section to the (already present) Caddyfile under ~/containers/caddy/config/Caddyfile
I won’t admit how long it took me to realize, that my Main Caddy container can’t communicate with a completely differnt caddy container, in a different pod, on a different network using localhost:8080.
Thanks to this excellent blog post, I was finally enlightened and released from my suffering.
Pod
Create the ~/.config/containers/systemd/nextcloud.pod file
To set up the backend Caddy instance, which will use the previously created Caddyfile, we simply create a new ~/.config/containers/systemd/nextcloud-caddy.container file
This will also forward the outside/system port 8080 to the inside port 80, specified in the aformentioned Caddyfile.
Database
Of course, Nextcloud requires a database. We’ll use MariaDB, as it’s one of the recommended choices for Nextcloud, according to the official documentation.
Apart from a performance standpoint, it doesn’t really matter, since we won’t clutter our system by using a containerized approach.
Podman Secret
First, we generate a Podman Secret to be used as the database password.
Warning
You should always generate this password!
Humans are not suitable password generators!
We use pwgen to generate a password and store it in a file, to not leak it to our shell history.
pwgen -s 32 1 > pass.txt
This generates a single 32 character long password and stores it in pass.txt.
We can now generate the Podman secret with the name nextcloud-mariadb-password
Please remember to purge the password file afterwards!
You can store the password securely in a password manager if you want, but you shouldn’t have unencrypted plaintext passwords on your system.
Container File
Create the ~/.config/containers/systemd/nextcloud-db.container file
For caching and other tasks, redis is a pretty standard choice. I actually planned to use Valkey, but ended up using redis for now.
Simply enough, I simply copied this container file.
Create the file under ~/.config/containers/systemd/nextcloud-redis.container:
Sometimes, the non-service-specific journal can be helpful in debugging a problem.
In that case, simply restart the service and immediately drop into the journal:
Look for Started Nextcloud Pod, to ensure Nextcloud has started successfully.
You can also check every other container’s status by substituting name with the container’s name.
Some maintenance tasks only run once a day.
To prevent them from being run during the main usage time, we can set the start of the maintenance window, as per the official documentation:
Security should be more than fine, by using rootless containers (even for the reverse proxy caddy), isolating the network, etc.
Still, security is always a concern and should be one of the top priorities.
I have collected a couple of additional options for the Backend Caddyfile that should harden the instance even more.
Most of these options aim at future-proofing the installation and, for example, prevent access to files which should be unproblematic, but might not be (in the future).
If you encounter weird problems or issues, it might be related to too restrictive of a config, so you might need to experiment with the introduced options, to determine which caused the error.
The file, we expand upon, is the Backend Caddyfile, as the frontend one solely describes the reverse proxy behavior.
The added/modified portions are highlighted, to enable quick expansion of an already existing (and hopefully working) ~/containers/nextcloud/caddy/config/Caddyfile file: