使用 docker 运行支持端口转发的 WireGuard + qBittorrent

最近有一些使用 bt 下载的需求,裸奔总是觉得稍微有点儿不踏实,于是考虑套一层 VPN。用 wireguard, qbittorent 和 nginx 拼了个 compose 文件,有同样需求的可以直接复制下来使用。配置文件中 wireguard 段的 56215 为我的 vpn 供应商的转发端口,还有 qbittorrent 段的 volumes 下载目录等都需要按照自己实际情况修改。

compose.yaml

version: "2.1"
services:

  wireguard:
    image: linuxserver/wireguard
    container_name: qb-wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Toronto
    volumes:
      - ./config:/config
      - /lib/modules:/lib/modules
    ports:
      - 56215:56215/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
      - net.ipv6.conf.all.disable_ipv6=0
    restart: unless-stopped

  qbittorrent:
    image: lscr.io/linuxserver/qbittorrent
    container_name: qbittorrent
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Toronto
      - WEBUI_PORT=9090
    volumes:
      - ./config:/config
      - ./watch:/watch
      - /data/downloads:/downloads
    network_mode: service:wireguard
    restart: unless-stopped

  nginx:
    image: nginx
    container_name: qb-nginx
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Toronto
    volumes:
      - ./config/nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - 9090:9090
    restart: unless-stopped

./config/nginx.conf


events {
  worker_connections 1024;
}

http {
  server {
    listen 9090;
    location / { 
      proxy_pass http://wireguard:9090;
    }   
  }
}

然后把 WireGuard 的配置文件放到 ./config/wg0.conf 就可以试着运行了。打开 ip:9090 应该可以看到 qBittorrent 的 web 管理界面,默认登录帐号是 admin/adminadmin。登录成功后进行最后的设置,把 Tools->Options->Advanced 里面的 Network Interface 设置为 WireGuard 设备,确保 VPN 不正常工作的情况下 qBittorrent 不会有网络流量。

This entry was posted in 我的慵懒生活 and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.