赞
踩
本人拥有一个国内云服务商的云主机和一个备案好的域名,通过caddy2来作为web服务器。我的云主机系统是Ubuntu。
我的云主机是公网ip,地址为:43.126.100.78;我备案好的域名是:hotgirl.com。后面的文章都以上述的ip和域名来进行讲解。
域名 hotgirl.com 已经通过云服务商的域名解析功能,解析到43.126.100.78。
我在云主机上安装了一个docker版本的headscale。通过caddy反向代理后的地址是:https://head.hotgirl.com。具体参看教程:Caddy2反向代理docker版本的headscale 。
具体参看教程:Caddy2反向代理docker版本的headscale 的第二部分内容。
firewall-cmd --add-port=15489/tcp --permanent
#重启防火墙
firewall-cmd --reload
#创建DERP中级服务器根目录
mkdir -p /docker/derp
version: "3"
services:
derper:
container_name: derper
image: fredliang/derper
restart: always
ports:
- 3478:3478/udp
- 15489:15489
environment:
DERP_DOMAIN: derper.hotgirl.com
DERP_ADDR: ":15489"
cd /docker/derp
docker-compose up -d
根据我前面的文章 Caddy2的安装、部署和编译小白教程 这篇文章中讲解的,修改Caddyfile这个文件:
vim /etc/caddy/Caddyfile
然后添加下面代码:
#Headscale
#中继服务器
derper.hotgirl.com {
tls {
get_certificate tailscale
}
reverse_proxy http://172.17.0.1:15489{
}
}
然后重启下caddy
systemctl reload caddy
如果 https://derper.hotgirl.com 打开后显示如下图,则说明中继服务器部署成功!
# /etc/headscale/derp.yaml
regions:
902:
regionid: 902
regioncode: sch
regionname: Home Sichuan
nodes:
- name: 902a
regionid: 902
hostname: 'derper.hotgirl.com'
ipv4: ''
stunport: 3478
stunonly: false
derpport: 443
上面的derp.yaml文件中,902 、902a 根据需要改成自己的regionid,总共四个地方,要改统一改掉。hostname就填写第六步中反代的中继服务器地址。
# DERP is a relay system that Tailscale uses when a direct # connection cannot be established. # https://tailscale.com/blog/how-tailscale-works/#encrypted-tcp-relays-derp # # headscale needs a list of DERP servers that can be presented # to the clients. derp: # List of externally available DERP maps encoded in JSON urls: - https://controlplane.tailscale.com/derpmap/default # Locally available DERP map files encoded in YAML # # This option is mostly interesting for people hosting # their own DERP servers: # https://tailscale.com/kb/1118/custom-derp-servers/ # paths: - /etc/headscale/derp.yaml #paths: [] # If enabled, a worker will be set up to periodically # refresh the given sources and update the derpmap # will be set up. auto_update_enabled: true # How often should we check for DERP updates? update_frequency: 24h
上面的代码路径 /etc/headscale/derp.yaml ,是容器内的路径,根据我的这篇 Caddy2反向代理docker版本的headscale 文章,回顾下headscale的docker-compose.yaml文件
version: '3.1'
services:
headscale:
image: headscale/headscale
container_name: headscale
volumes:
- /docker/headscale/config:/etc/headscale
- /docker/headscale/data:/var/lib/headscale
- /docker/headscale/run:/var/run/headscale
ports:
- '0.0.0.0:8181:8181'
- '0.0.0.0:9191:9191'
command: headscale serve
restart: unless-stopped
可以看出来,容器内路径“/etc/headscale” 是映射到了服务器路径 “/docker/headscale/config” ,所以我们只需把derp.yaml放入“/docker/headscale/config” 路径内,并文件名对应即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。