Docker Compose stack to deploy a WireGuard VPN server (wg-easy), Traefik as a reverse proxy to access the wg-easy
UI, and Authelia for authentication.
-
Ensure Docker and Docker Compose plugin are installed.
-
Download the latest version of the source code from the release page:
RELEASE=0.0.1 curl -L -o wireguard-traefik-authelia-${RELEASE}.zip https://github.com/veerendra2/wireguard-traefik-authelia/archive/refs/tags/v${RELEASE}.zip unzip wireguard-traefik-authelia-${RELEASE}.zip cd wireguard-traefik-authelia-${RELEASE}
-
Generate a password hash for users in Authelia:
docker run --rm authelia/authelia:latest \ authelia crypto hash generate argon2 \ --password 'YOUR_PASSWORD'
-
Update the Authelia users configuration in
./config/users_database.yml
:users: your-user-name: disabled: false displayname: "Your Display Name" password: "<generated-password-hash>" email: "root@localhost"
-
Open the following ports on your server for the WireGuard stack:
- 80 (TCP)
- 443 (TCP)
- 22 (TCP)
- 51820 (UDP)
This setup has been tested with DuckDNS and Cloudflare. It should work with other DNS providers with appropriate configurations.
-
Log in to DuckDNS and retrieve your token.
-
Create a subdomain and add your server's IP address.
-
Export the required environment variables and start the Docker stack:
export MY_PROVIDER="duckdns" export MY_DOMAIN="YOUR_SUB_DOMAIN.duckdns.org" export DUCKDNS_TOKEN="MY_DUCKDNS_TOKEN" docker compose up -d
-
Log in to Cloudflare and navigate to your domain.
-
Click on "DNS" and add the following subdomains as "A" records, pointing to your server's IP address:
wg.<YOUR_SUB_DOMAIN>
auth.<YOUR_SUB_DOMAIN>
<YOUR_SUB_DOMAIN>
For example, if
<YOUR_SUB_DOMAIN>
isxyz
, the records should be configured as shown below:Note: Ensure that Cloudflare proxy is disabled while adding these subdomains, as shown below:
-
To generate a Cloudflare API token:
- Go to "Profile" → "API Token" → Click "Create Token".
- Scroll down and click "Get started" under "Custom token".
- Assign the necessary permissions.
-
Export the required environment variables and start the Docker stack:
export MY_PROVIDER="cloudflare" export MY_DOMAIN="YOUR_SUB_DOMAIN.YOUR_DOMAIN_NAME.com" export CLOUDFLARE_DNS_API_TOKEN="MY_CLOUDFLARE_TOKEN" docker compose up -d
-
Once the stack is running, visit
wg.${MY_DOMAIN}
, log in, and register. -
After logging in, click "ADD" to set up OTP authentication.
-
Retrieve the initial 2FA code from
config/notification.txt
.cat config/notification.txt
Example Output:
Date: 2024-07-21 14:55:11 UTC Recipient: Test User <[email protected]> Subject: Confirm your identity To confirm your identity, use the following code: TXQAT55T
-
Register the OTP in your preferred authenticator app.
-
Log in, configure your clients, and verify VPN connectivity via whoer.net.