惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

Jiajun的技术笔记

你好,2026! TiDB 源码阅读(六):TiDB Coprocessor 源码解析 性能优化的核心思想 TiDB 源码阅读(五):索引 TiDB 源码阅读(四):AST、逻辑计划、物理计划 CockroachDB Serverless Architecture podman 无故退出 Cursor Control-L (CTRL-L) Keyboard Shortcuts in Terminal Replace docker with podman Using xmonad with xfce4 A RC script for freebsd frpc 自己动手写一个k8s controller AI 会取代你的(编程)岗位吗? 自动升级Docker容器 再读《程序员修炼之道-从小工到专家》 让浏览器下载文件 再读《软件随想录》/《黑客与画家》/《软技能》 HTTP 压力测试中的 Coordinated Omission 2的补码 编程语言中的 context 是什么? flutter macOS 构建出错 Flatpak 使用小记 Golang CAS 操作是怎么实现的 PostgreSQL 当MQ来使用 Clash 结合 工作VPN 的网络设计 使用 PostgreSQL 搭建 JuiceFS PostgreSQL 配置优化和日志分析 有GitHub Copilot?那就可以搭建你的ChatGPT4服务 窗口函数的使用(以PG为例) 读《为什么学生不喜欢上学》
自建DERP服务器提升Tailscale连接速度(使用Nginx转发)
Jiajun Huang · 2024-11-20 · via Jiajun的技术笔记

官方文档里,DERP服务器默认是直接占用443端口的,但是我的服务器上已经有了Nginx服务,因此好一顿折腾,终于成功了。

安装DERP

我没有使用 Docker 镜像,而是直接二进制+systemd的方式安装的(首先你得分配一个域名指向这个机器):

# go install tailscale.com/cmd/derper@latest
# cp ~/go/bin/derper /usr/local/bin/

然后编辑/etc/systemd/system/derper.service

[Unit]
Description=My Derper Service
After=network.target

[Service]
ExecStart=/usr/local/bin/derper -hostname=<域名,后面还会用> -a :30001 -http-port 30001 -stun-port 3478 -verify-clients
Restart=on-failure
User=root

[Install]
WantedBy=multi-user.target

然后systemctl enable derper && systemctl start derper

配置Nginx

增加如下Nginx配置文件:

server {
    listen 80;
    listen 443 ssl;
    server_name <域名>;

    access_log <Nginx 日志路径>;
    error_log <Nginx 错误日志路径>;

    ssl_certificate <Let's Encrypt 证书路径>;
    ssl_certificate_key <Let's Encrypt 证书私钥路径>;

    location / {
        client_max_body_size 1G;

        # websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        # other settings
        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;
        proxy_pass http://127.0.0.1:30001;
    }
}

请注意,这里 WebSocket 的配置是必须的,否则 Tailscale 无法正常工作,我掉到这个坑好久才爬出来。

参考掉坑 issue: https://github.com/tailscale/tailscale/issues/4072

配置 ACL 规则

打开 tailscale 的管理页面,添加 ACL 规则,允许你的域名访问 DERP 服务器。

ssh 同级,添加:

// Define private derp
"derpMap": {
    "omitDefaultRegions": false,
    "regions": {
        "901": {
            "regionID":   901,
            "regionCode": "MyHK",
            "regionName": "My HongKong",
            "nodes": [
                {
                    "name":     "myhk",
                    "regionID": 901,
                    "hostName": "<域名>",
                    "DERPPort": 443,
                    "IPv4":     "<机器IP>",
                    "IPv6":     "none", // 如果你的服务器没有 IPv6
                    //"InsecureForTests": true,
                    "STUNPort": 3478,
                },
            ],
        },
    },
},

// ssh...

然后重启 tailscaled 服务,systemctl restart tailscaled

就可以使用自有 DERP 服务器了,速度飞起。