1. Caddy version (caddy version
):
pi@naspi:~/rpi4_server $ docker images | grep caddy
caddy latest 8b01501010b8 6 days ago 31.7MB
2. How I run Caddy:
Using docker-compose file, an .env file and a Caddyfile.
a. System environment:
Running on a Raspberrypi 4, 4gb with classic Raspberrypi OS (debian)
pi@naspi:~/rpi4_server $ docker --version
Docker version 19.03.13, build 4484c46
pi@naspi:~/rpi4_server $ docker-compose --version
docker-compose version 1.27.4, build unknown
Installed docker-compose with pip3 as armv7 does not have a suitable package from github.
b. Command:
# full homeserver
docker-compose up -d
# just caddy
docker-compose up caddy
c. Service/unit/compose file:
version: "3.8"
services:
sonarr:
image: linuxserver/sonarr
container_name: sonarr
restart: unless-stopped
ports:
- "${SONARR_PORT}:8989"
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TIMEZONE}
volumes:
- ${APPDATA_ROOT}/sonarr:/config
- ${MEDIA_ROOT}:/media
radarr:
image: linuxserver/radarr
container_name: radarr
restart: unless-stopped
ports:
- "${RADARR_PORT}:7878"
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TIMEZONE}
volumes:
- ${APPDATA_ROOT}/radarr:/config
- ${MEDIA_ROOT}:/media
jackett:
image: linuxserver/jackett
container_name: jackett
restart: unless-stopped
ports:
- "${JACKETT_PORT}:9117"
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TIMEZONE}
volumes:
- ${APPDATA_ROOT}/jackett:/config
- ${APPDATA_ROOT}/jackett/downloads:/downloads
heimdall:
image: linuxserver/heimdall
container_name: heimdall
restart: always
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TIMEZONE}
ports:
- "${HEIMDALL_PORT}:80"
- "${HEIMDALL_SSL_PORT}:443"
volumes:
- ${APPDATA_ROOT}/heimdall:/config
qbittorrent:
image: linuxserver/qbittorrent
container_name: qbittorrent
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TIMEZONE}
- WEBUI_PORT=${QBITTORRENT_PORT}
volumes:
- ${APPDATA_ROOT}/qbittorrent:/config
- ${MEDIA_ROOT}/downloads:/downloads/media
- ${EXECUTABLES_ROOT}/downloads:/downloads/executables
ports:
- 6881:6881
- 6881:6881/udp
- "${QBITTORRENT_PORT}:${QBITTORRENT_PORT}"
restart: unless-stopped
plex:
image: linuxserver/plex
container_name: plex
network_mode: host
ports:
- "${PLEX_PORT}:32400"
environment:
- PUID=${PUID}
- PGID=${PGID}
- VERSION=docker
- PLEX_CLAIM=claim-REDACTED #optional
volumes:
- ${APPDATA_ROOT}/plex:/config
- ${MEDIA_ROOT}:/media
restart: unless-stopped
devices:
- /dev/dri:/dev/dri #optional
- /dev/vcsm:/dev/vcsm #optional
- /dev/vchiq:/dev/vchiq #optional
- /dev/video10:/dev/video10 #optional
- /dev/video11:/dev/video11 #optional
- /dev/video12:/dev/video12 #optional
samba:
image: dperson/samba
container_name: samba
ports:
- "137:137/udp"
- "138:138/udp"
- "139:139/tcp"
- "445:445/tcp"
environment:
- TZ=${TIMEZONE}
volumes:
- ${APPDATA_ROOT}:/appdata
- ${MEDIA_ROOT}:/media
- ${CLOUD_ROOT}:/cloud
- ${EXECUTABLES_ROOT}:/executables
restart: unless-stopped
# need to add all of the volumes here in the command.
# the yes;no; stuff is for setting permissions
command: '-s "Appdata";/appdata;yes;no;yes;;;;
-s "Media";/media;yes;no;yes;;;;
-s "Cloud";/cloud;yes;no;yes;;;;
-s "Executables";/executables;yes;no;yes;;;;'
portainer:
image: portainer/portainer
container_name: portainer
restart: always
ports:
- "${PORTAINER_PORT}:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${APPDATA_ROOT}/portainer:/data
caddy:
container_name: caddy
image: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
env_file:
- .env
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
# - $PWD/site:/srv
- ${APPDATA_ROOT}/caddy/data:/data
- ${APPDATA_ROOT}/caddy/config:/config
d. My complete Caddyfile or JSON config:
naspi.local {
# default -> pihole
# reverse_proxy 192.168.0.69:443
redir /heimdall /heimdall/
reverse_proxy /heimdall/* 192.168.0.69:{$HEIMDALL_PORT}
redir /portainer /portainer/
reverse_proxy /portainer/* 192.168.0.69:{$PORTAINER_PORT}
# media
redir /sonarr /sonarr/
reverse_proxy /sonarr/* 192.168.0.69:{$SONARR_PORT}
redir /radarr /radarr/
reverse_proxy /radarr/* 192.168.0.69:{$RADARR_PORT}
redir /jackett /jackett/
reverse_proxy /jackett/* 192.168.0.69:{$JACKETT_PORT}
redir /plex /plex/
reverse_proxy /plex/* 192.168.0.69:{$PLEX_PORT} #{
# encode gzip
# header {
# Strict-Transport-Security max-age=31536000;
# X-Content-Type-Options nosniff
# X-Frame-Options DENY
# Referrer-Policy no-referrer-when-downgrade
# X-XSS-Protection 1
# }
#}
# cloud
redir /nextcloud /nextcloud/
reverse_proxy /nextcloud/* 192.168.0.69:{$NEXTCLOUD_PORT}
# torrent
#redir /qbittorrent /qbittorrent/
#reverse_proxy /qbittorrent/* 192.168.0.69:{$QBITTORRENT_PORT} {
# without /qbittorrent
# transparent
# websocket
# header_upstream X-Forwarded-Host 192.168.0.69:{$QBITTORRENT_PORT}
# header_upstream -Origin
# header_upstream -Referer
}
}
3. The problem I’m having:
I’m trying to get a working reverse proxy setup on each of my services that I run on my Rpi 4. I have sucessfully reversed sonarr, radarr and jackett as there was a lot to find on the internet. Qbittorrent / plex are not as easy and after reading the reverse_proxy directives I don’t understand what I need to add to get it working.
First I would like to reverse proxy everything in my local domain, by accessing in my example naspi.local/serviceXX or naspi.local/serviceYY. I would prefer if it was serviceXX.naspi.local but as far as I understand this is not possible in the local network. Any tips regarding this are helpful.
Secondly, after my local reverse proxy is operational I want to also point to a domain I own.
4. Error messages and/or full log output:
Just getting white pages / nothing is rendered.
Plex error : 401 unauthorized
Qbittorrent: no page rendered
5. What I already tried:
I’ve already tried several things, as can be seen commented in the Caddyfile, but I just don’t know where to begin with writing these directives.
Most of the things I can find on reverse proxying for example qbittorrent are from the V1 version and I’m not entirely sure how to migrate them to v2. I’ve tried several options, such as adding the header_upstream for X-forwarded, or the transparent option. Also, I’ve tried disabling CSRF in qbittorrent, but to no avail.
I can also not find a generic home server Caddy v2 configuration and this can contribute greatly to the community as a guideline for others.
6. Links to relevant resources:
https://www.reddit.com/r/PleX/comments/5t6udh/how_to_reverse_proxy_plex_and_others_using_caddy/