Skip to content

Instantly share code, notes, and snippets.

@lnxph-devops-sareno
Last active December 9, 2025 07:22
Show Gist options
  • Select an option

  • Save lnxph-devops-sareno/c5f2af568628055124c7a6589d3d2681 to your computer and use it in GitHub Desktop.

Select an option

Save lnxph-devops-sareno/c5f2af568628055124c7a6589d3d2681 to your computer and use it in GitHub Desktop.
Easy-Wireguard

Docker Compose

File: docker-compose.yaml

volumes:
  etc_wireguard:

services:
  wg-easy:
    environment:
    #  Optional:
    #  - PORT=51821
    #  - HOST=0.0.0.0
      - INSECURE=true

    image: ghcr.io/wg-easy/wg-easy:15
    container_name: wg-easy
    networks:
      wg:
        ipv4_address: 10.42.42.42
        ipv6_address: fdcc:ad94:bacf:61a3::2a
    volumes:
      - etc_wireguard:/etc/wireguard
      - /lib/modules:/lib/modules:ro
    ports:
      - "51820:51820/udp"
      - "51821:51821/tcp"
    restart: unless-stopped
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
      # - NET_RAW # ⚠️  Uncomment if using Podman
    sysctls:
      - net.ipv4.ip_forward=1
      - net.ipv4.conf.all.src_valid_mark=1
      - net.ipv6.conf.all.disable_ipv6=0
      - net.ipv6.conf.all.forwarding=1
      - net.ipv6.conf.default.forwarding=1

networks:
  wg:
    driver: bridge
    enable_ipv6: true
    ipam:
      driver: default
      config:
        - subnet: 10.42.42.0/24
        - subnet: fdcc:ad94:bacf:61a3::/64

Run:

$ docker compose up -d

Nginx Confi

server {
    listen 80;
    server_name vpn.example.com; 

    location / {
        # Forward traffic to wg-easy on port 51821
        proxy_pass http://127.0.0.1:51821;

        # WebSocket Support (Required for stats)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Standard Headers
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # Disable buffering for real-time responsiveness
        proxy_buffering off;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment