Self-host a WireGuard VPN with wg-easy in Docker: web UI, HTTPS and DDNS
WireGuard is a fast, modern VPN built into the Linux kernel. On its own it is configured with text files and key pairs, which gets tedious once you have several phones and laptops. wg-easy wraps WireGuard in a small web interface: you click to add a client, then scan a QR code or download a config file.
This guide shows a setup that works well for a home server or small VPS:
- WireGuard and the wg-easy web interface run in one Docker container.
- The VPN port (UDP) is public, on its own hostname.
- The admin interface is private, reachable only from inside your network through a reverse proxy with HTTPS.
Everything uses placeholder names. Replace vpn.example.com, wg-admin.example.com and the IP addresses with your own.
How the pieces fit together
vpn.example.com: a DNS-only record pointing at your public IP. Clients connect to it on UDP 51820. It is not proxied, because Cloudflare's proxy handles web traffic, not WireGuard.wg-admin.example.com: the web interface, served by Caddy over HTTPS. A local DNS rewrite resolves it to a private address, and Caddy refuses requests that do not come from a private network.- wg-easy container: creates the WireGuard interface, stores keys and generates client configs.
Requirements
- A Linux host, VM or LXC container with Docker and Docker Compose
- A reverse proxy already running in Docker (this guide uses Caddy on a shared network called
proxy) - A domain you control, and the ability to forward one UDP port on your router or firewall
- A way to keep DNS current if your public IP changes (see Keep a dynamic home IP updated in Cloudflare DNS)
If your internet provider uses CGNAT, you will not receive inbound connections at home, and you need a small VPS to host the VPN instead.
Running inside an LXC container
An LXC container shares the host's kernel, so WireGuard has to be available there and the container must be allowed to use it:
- The host kernel needs WireGuard support. Many current kernels include it, and you can check with
lsmod | grep wireguardon the host. - The container needs the TUN device. On Proxmox, add these lines to the container's file in
/etc/pve/lxc/and restart the container:
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
- Docker inside the container usually needs nesting enabled in the container's options.
Check that /dev/net/tun exists inside the container before you continue.
1. Folder layout and environment file
sudo mkdir -p /opt/wireguard/wireguard
cd /opt/wireguard
Create .env with the values you may want to change later:
WG_PORT=51820
The wireguard folder will hold the generated keys and config, so it is the part you need to back up.
2. The Compose file
wg-easy version 15 moved most settings out of environment variables and into the web interface, so the compose file stays short. Create /opt/wireguard/compose.yaml:
services:
wg-easy:
image: ghcr.io/wg-easy/wg-easy:15
container_name: wg-easy
restart: unless-stopped
env_file: .env
environment:
- INSECURE=true # TLS is handled by the reverse proxy
volumes:
- ./wireguard:/etc/wireguard
- /lib/modules:/lib/modules:ro
ports:
- "${WG_PORT}:51820/udp" # VPN traffic only
cap_add:
- NET_ADMIN
- SYS_MODULE
sysctls:
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.src_valid_mark=1
networks:
- proxy
networks:
proxy:
external: true
Points worth understanding:
- Only the UDP port is published. The web interface (port 51821 inside the container) has no
ports:entry, so it is reachable only from other containers on theproxynetwork, which means Caddy. INSECURE=truelets the interface accept plain HTTP from the proxy. wg-easy 15 normally insists on HTTPS, so only use this when a reverse proxy ends TLS in front of it, and never expose the port directly.NET_ADMINand the sysctls let the container create the WireGuard interface and forward packets between the tunnel and the network.
Start it:
docker compose up -d
docker compose logs -f wg-easy
If the logs show an error about creating the interface, revisit the LXC notes above.
3. Publish the admin interface privately
Add a site block to Caddy. This one answers only when the request comes from a private address range and returns a 403 to everyone else:
wg-admin.example.com {
@internal remote_ip private_ranges
handle @internal {
reverse_proxy wg-easy:51821
}
handle {
respond "Forbidden" 403
}
}
Reload Caddy afterwards. Two things need attention:
- A certificate for an internal name. Caddy normally proves ownership with a public HTTP challenge, which fails if the hostname does not point at your server publicly. The clean solution is the DNS challenge, which needs a Caddy build with your DNS provider's plugin. The simpler option is
tls internal, which uses Caddy's own certificate authority, but browsers warn until you trust its root certificate. - A local DNS record. Create a DNS rewrite on your local resolver so
wg-admin.example.comresolves to the private address of the machine running Caddy. See Run AdGuard Home in Docker for how to add one. Do not create a public record for this name.
4. First-run setup
Open https://wg-admin.example.com from inside your network. The setup wizard asks you to create the administrator account. Choose a long, unique password.
Then open the administrator settings and set:
- Public host:
vpn.example.com. This goes into every client config as the endpoint. - Public port: the port clients will use,
51820unless you changed it. - DNS servers for clients: your local resolver if you run one, or a public resolver otherwise.
Check the tunnel's address range in the settings as well. The default is a private range such as 10.8.0.0/24. Make sure it does not overlap with your home network.
5. Publish the VPN port
- DNS: create an A record for
vpn.example.compointing at your public IP, set to DNS only (grey cloud). If your IP changes, keep it updated with a DDNS container. - Router or firewall: forward UDP 51820 to the machine running the container. On a cloud server, allow UDP 51820 in the security group as well.
- Host firewall: allow UDP 51820 and forwarding for the tunnel interface.
Confirm the port is listening on the host:
sudo ss -ulnp | grep 51820
6. Add clients
In the web interface, create a client for each device and give it a name that identifies the device, such as phone or laptop. Each client gets its own keys.
- Phone: install the WireGuard app, choose to add a tunnel from a QR code, and scan the code shown in wg-easy.
- Laptop: download the config file and import it into the WireGuard application.
The client's Allowed IPs setting decides what goes through the VPN:
0.0.0.0/0, ::/0sends all traffic through the tunnel (a full tunnel). Use this on public Wi-Fi.- Only your home subnet and the tunnel range (a split tunnel) sends just traffic for your own network and leaves the rest on the normal connection.
Choose per device, and edit it in the client's settings if you change your mind.
7. Test it
Turn on mobile data on a phone with the tunnel enabled, which means the phone is outside your network, and check:
sudo docker exec wg-easy wg show
A working client shows a recent "latest handshake" and growing transfer counters. From the phone, try opening an internal service by its private address. With a full tunnel, a "what is my IP" website should show your home's public IP address.
Security checklist
- Keep the admin interface private. If it ever needs to be reachable from outside, put a second layer of authentication in front of it.
- Publish only the UDP port, and nothing else from this container.
- Use one client per device, so you can revoke a lost phone without touching the others.
- Keep the image updated and the host patched.
- Back up
/opt/wireguard/wireguardand the.envfile. Without the keys you would have to reissue every client.
Updates and backups
cd /opt/wireguard
docker compose pull
docker compose up -d
Read the release notes before moving to a new major version, because wg-easy has changed how it is configured between major versions.
Troubleshooting
- No handshake at all: the packets are not reaching the server. Check the DNS record, the port forward, any cloud security rules, and CGNAT.
sudo tcpdump -ni any udp port 51820on the host shows whether anything arrives. - Handshake works but there is no internet or no access to your network: forwarding or NAT is the usual cause. Confirm the sysctls are applied inside the container and that the host firewall allows forwarding.
- The interface will not come up in an LXC: check
/dev/net/tun, the WireGuard module on the host and the container options. - The web interface refuses to load or log in: it needs HTTPS, or
INSECURE=truebehind a proxy. Also check that you are on the private network, because the Caddy rule returns 403 elsewhere. - Endpoint stops working after an IP change: your DDNS record is stale. Check that the updater is running.
- Slow or stalled connections for large transfers: try lowering the client's MTU setting.
- DNS leaks: make sure the client's DNS servers are set to a resolver reachable through the tunnel.
Summary
wg-easy turns WireGuard into something you can manage from a browser. Keep the VPN port public and the admin page private, give each device its own client, and back up the config folder. The result is a small, fast VPN that you control completely.