Adding SSL to a Docker installation
To open FileRun with HTTPS, place a reverse proxy in front of its container. This page adds Caddy,
Nginx Proxy Manager or Traefik to the docker-compose.yml of the Docker guide, or to the
stack of the Dockhand guide or the Portainer guide.
- Caddy is the simplest. It needs only the domain name, and gets and renews the certificate by itself.
- Nginx Proxy Manager is set up in its own web interface, which suits a server that serves several sites.
- Traefik is set up with labels on the containers, which suits a server that runs many containers, or one that already uses Traefik.
Before you start
You need:
- A domain name, such as
files.example.com, that points at the server. - The ports 80 and 443 of the server, free and reachable from the internet. Let's Encrypt connects to them to check that the domain is yours before it issues the certificate.
The examples show only the services to add or change, with [...] in place of the rest of the
file. Replace files.example.com with your domain name. To apply a change:
- with Docker Compose, run
docker compose up -din the folder ofdocker-compose.yml, - in Dockhand, open the stack in Stacks, change it in its editor and click Save & redeploy,
- in Portainer, open the stack in Stacks, change it in its Editor tab and click Update the stack.
Caddy
Caddy gets a certificate from Let's Encrypt for the domain name, renews
it, and sends the visitors of http:// to https://.
Add the service proxy, and remove the ports of FileRun, which is then reached only through the
proxy:
1services:
2 [...]
3 web:
4 image: filerun/filerun
5 [...]
6 # no "ports" here
7 proxy:
8 image: caddy:2
9 restart: unless-stopped
10 command: caddy reverse-proxy --from files.example.com --to web:80
11 ports:
12 - "80:80"
13 - "443:443"
14 volumes:
15 - /filerun/caddy:/data
/filerun/caddy keeps the certificates, so that Caddy does not ask for new ones every time it
starts.
Open https://files.example.com. If the page does not open, the log of the proxy shows whether the
certificate was issued, or why not: docker compose logs proxy, or the log of the container in
Dockhand or Portainer.
Caddy needs nothing else: it passes on the host name, the protocol and the IP address of the visitor, sets no limit on the size of an upload, and passes the upload on as it arrives, so an interrupted upload can be resumed.
Nginx Proxy Manager
Nginx Proxy Manager (NPM) is set up in its own web interface, where you add FileRun as a proxy host and request its certificate.
Add the service proxy, and move FileRun to the port 8080, since NPM takes the port 80:
1services:
2 [...]
3 web:
4 image: filerun/filerun
5 [...]
6 ports:
7 - "8080:80"
8 proxy:
9 image: 'jc21/nginx-proxy-manager:latest'
10 restart: unless-stopped
11 ports:
12 - '80:80'
13 - '81:81'
14 - '443:443'
15 volumes:
16 - /filerun/proxy/data:/data
17 - /filerun/proxy/letsencrypt:/etc/letsencrypt
Make sure FileRun is up and running (http://your-server:8080).
Open the admin console of NPM on the port 81 (http://your-server:81).
Go to Hosts → Proxy Hosts and click Add Proxy Host.
- If NPM runs in the same
docker-compose.ymlor stack as FileRun, use the hostnameweb, the name of the FileRun service, and the port80. The proxying is then done through the Docker network. - If FileRun runs on a different server, use the IP address of that server and the port
8080.
Under the SSL tab, choose Request a new SSL certificate.
And click Save.
NPM fetches the certificate, installs it, and sets up the HTTPS proxy to FileRun. You should now be
able to open https://files.example.com in your browser.
When NPM reaches FileRun through the Docker network, FileRun needs no port of its own: once the
proxy host works, remove the ports of FileRun, so that nobody reaches it around the proxy.
Make the proxy transparent
Without the correct HTTP Host header being forwarded from NPM to the FileRun server, FileRun won't know that it is being accessed via a domain name.
Click the cog icon to access the Advanced configuration tab. Paste the following inside:
1proxy_set_header Host $host;
2proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3proxy_set_header X-Forwarded-Proto $scheme;
4proxy_set_header X-Forwarded-Protocol $scheme;
5proxy_set_header X-Forwarded-Port $server_port;
Enabling streaming upload
In the same place as above, paste also this line:
1proxy_request_buffering off;
This will enable streaming and allow you to resume uploads from the exact byte where it was interrupted.
Traefik
Traefik finds the containers to serve through Docker, by their labels, and gets a certificate from Let's Encrypt for each.
Add the service proxy, give FileRun the labels below, and remove the ports of FileRun, which is
then reached only through the proxy:
1services:
2 [...]
3 web:
4 image: filerun/filerun
5 [...]
6 # no "ports" here
7 labels:
8 - traefik.enable=true
9 - traefik.http.routers.filerun.rule=Host(`files.example.com`)
10 - traefik.http.routers.filerun.entrypoints=https
11 - traefik.http.routers.filerun.tls.certresolver=letsencrypt
12 - traefik.http.services.filerun.loadbalancer.server.port=80
13 proxy:
14 image: traefik:v3
15 restart: unless-stopped
16 command:
17 - --providers.docker.exposedbydefault=false
18 - --entrypoints.http.address=:80
19 - --entrypoints.http.http.redirections.entrypoint.to=https
20 - --entrypoints.http.http.redirections.entrypoint.scheme=https
21 - --entrypoints.https.address=:443
22 - --entrypoints.https.transport.respondingTimeouts.readTimeout=0
23 - --certificatesresolvers.letsencrypt.acme.tlschallenge=true
24 - --certificatesresolvers.letsencrypt.acme.email=you@example.com
25 - --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
26 ports:
27 - "80:80"
28 - "443:443"
29 volumes:
30 - /var/run/docker.sock:/var/run/docker.sock:ro
31 - /filerun/traefik:/letsencrypt
- Replace
you@example.comwith your e-mail address, where Let's Encrypt writes about the certificate. It refuses the addresses ofexample.com. - Keep the line with
readTimeout=0. Without it, Traefik stops every request that is still arriving after 60 seconds, and the upload of a large file fails on a slower connection. /filerun/traefikkeeps the certificates, so that Traefik does not ask for new ones every time it starts.- Traefik reads the containers and their labels through the Docker socket. With
exposedbydefault=false, it serves only the containers labeledtraefik.enable=true.
Open https://files.example.com. If the page does not open, the log of the proxy shows whether the
certificate was issued, or why not.
If Traefik already runs on the server, add only the labels to FileRun, with the names of your own
entry point and certificate resolver, and connect FileRun to a Docker network of Traefik. Set the
readTimeout of that entry point to 0 as above.
Traefik needs nothing else: it passes on the host name, the protocol, the port and the IP address of the visitor, sets no limit on the size of an upload, and passes the upload on as it arrives.
Other reverse proxies
Any other reverse proxy works too, such as
HAProxy. Make sure it passes the
Host header unchanged, and at least one of X-Forwarded-Proto, X-Forwarded-SSL and
X-Forwarded-Port. FileRun looks for any of these to determine if the URLs should start with HTTP
or HTTPS, and to forward requests via the correct HTTP port.
When using NGINX, just add this line in your conf file, in the location block:
proxy_set_header X-Forwarded-Proto https;
See Reverse proxies for the rest of the settings.
After the proxy is set up
Trusted proxies
Every request now reaches FileRun from the proxy, so FileRun records the IP address of the proxy as
the IP address of every user, until you fill in Trusted proxies under System → Settings in
the control panel. See Trusted proxies.
When the proxy runs in the same docker-compose.yml or stack as FileRun, enter the subnet of their
Docker network, such as 172.20.0.0/16, which this command shows:
1docker network inspect filerun_default --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}'
filerun_default is the network of the stack filerun in Dockhand or Portainer. With Docker
Compose, the name starts with the name of the folder of docker-compose.yml instead.
docker network ls lists them.
The subnet can change when the network is created again, such as after docker compose down, so
check it then.
Locking the URL
Open FileRun once on https://files.example.com, then turn on Lock the URL under System →
Settings, so that FileRun answers only on that URL. See
Locking the URL.