最近在架 KVM 使用 WebVirtCloud 做網頁遠端控制 VM,之前研究 Ubuntu 啟用 VNC 是為了能控制 VM GUI 介面,但是在公司沒法連線使用,這邊有找到 WebVirtCloud 可以解決這個問題,透過這個服務可能用 Traefik 轉服務出去,透過 Authelia 做 2FA 驗證可以相當方便,但我發現我不會轉 host 服務出去,這邊就特別研究怎麼用。
設定方法
- 設定 Traefik services 檔案
- 新增 Traefik file providers
- 設定 docker-compose.yml 的 Volume
- 重啟 docker-compose
Traefik 設定 services.toml
services.toml
1
2
3
4
5
6
7
8
9
10
11
|
[http]
[http.services]
[http.services.__name__]
[http.services.__name__.loadBalancer]
[[http.services.__name__.loadBalancer.servers]]
url = "http://192.168.1.XX/"
[http.routers]
[http.routers.__name__]
tls = "true"
rule = "Host(`test.xxxxx.duckdns.org`)"
service = "__name__"
|
__name__ 可更換名稱。相關配置可看官網文件,這邊修改就能完成。
新增 Traefik file providers
這邊可以在 traefil.yml 設定,但我選擇使用 docker-compose.yml 配置,因為我只要改一個文件就能完成所有事情。
1
2
3
|
providers:
file:
filename: /path/to/config/dynamic_conf.yml
|
1
|
--providers.file.filename=/path/to/config/dynamic_conf.yml
|
這邊我們要改在 docker-compose 裡面的 cli。
設定 docker-compose.yml 的 Volume
1
2
3
4
5
|
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./acme.json:/acme.json
#- ./traefik.yml:/etc/traefik/traefik.yml 因為我用 docker-compose.yml 所以就沒用這個
- ./services.toml:/etc/traefik/services.toml
|
traefik.yml 因為我用 docker-compose.yml 所以就沒用這個。主要是 ./services.toml:/etc/traefik/services.toml。
重啟 traefik
因為架在 docker,所以重啟 docker-compose。
1
|
docker-compose down && docker-compose up -d
|
完成可以做簡單確認。

這邊下面我就做其他紀錄。我其他文章都有做紀錄,這邊做個懷舊紀錄。
加料
authelia 設定登入驗證
1
2
3
4
5
|
labels:
- "traefik.http.routers.vm.rule=Host(`xxx.xxxx.duckdns.org`)"
- "traefik.http.routers.vm.tls=true"
- "traefik.http.services.vm.loadbalancer.server.port=80"
- 'traefik.http.routers.vm.middlewares=authelia@docker'
|
重點是這一行- 'traefik.http.routers.vm.middlewares=authelia@docker'。但我們變成 services.toml,所以相對應設定都要調整。
1
2
3
4
5
6
7
8
9
10
11
12
|
[http]
[http.services]
[http.services.__name__]
[http.services.__name__.loadBalancer]
[[http.services.__name__.loadBalancer.servers]]
url = "http://192.168.1.XX/"
[http.routers]
[http.routers.__name__]
tls = "true"
rule = "Host(`test.xxxxx.duckdns.org`)"
service = "__name__"
middlewares = "authelia@docker"
|
至於 middleware 就參考我其他片設定。這邊就不再寫了。
彩蛋