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

推荐订阅源

罗磊的独立博客
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
C
Check Point Blog
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG

Dallas Lu

一些没有意义的事情 博客程序的一次大重构 OpenWRT 使用 udp2raw 对抗 WireGuard 阻断 OpenWRT 使用 udp2raw 对抗 WireGuard 阻断 博客程序架构的思考与展望 如何证明你是原创作者 如何证明你是原创作者 Nginx 泛域名配置的隐患与对策 Nginx 泛域名配置的隐患与对策 WISeID S/MIME 证书 WISeID S/MIME 证书 V2EX 刑满释放记 V2EX 刑满释放记 使用 Radicale 在 Ubuntu 24.04 中搭建 vCards CardDav 服务 使用 Radicale 在 Ubuntu 24.04 中搭建 vCards CardDav 服务 邮件服务的域名成功从 SURBL 黑名单移除 邮件服务的域名成功从 SURBL 黑名单移除 网站多语言的设计细节 网站多语言的设计细节 网站评论系统的目前进展和展望 网站评论系统的目前进展和展望 在公网使用 iptables 转发端口时保留客户端 IP 在公网使用 iptables 转发端口时保留客户端 IP 邮件投递平台 Postal 的使用经验 邮件投递平台 Postal 的使用经验 自建 Postal 完美替代 SendGrid 自建 Postal 完美替代 SendGrid 互联网在崩塌吗,然后呢 互联网在崩塌吗,然后呢 在 SvelteKit 应用中使用 JSON-LD
使用你的主域名作为 Mastodon 实例名
达拉斯・卢 · 2020-11-10 · via Dallas Lu

如果你有一个自建的博客,并且打算或已经建立一个 Mastodon 实例,那么就不得不面对一个域名选择的问题了。假设你的博客是 example.com,那么你的 Mastodon 账号应该是 yourname@example.com 还是 yourname@mastodon.example.com

为了简单明了,你自然更希望博客域名和 Mastodon 域名是同一个。但是 Mastodon 无法运行在二级目录下。即使通过反代等手段,把 Mastodon 的 web 部分,转移到了某个二级域名或目录下,那么作为一个去中心化的服务,在与联邦宇宙其他实例节点交换数据时,很可能发生未知的问题。

幸运的是,联邦节点间通信的重要一步是访问 https://example.com/.well-known/host-meta,这个文件的内容中包含了供后续步骤使用的 URL。而且 Mastodon 也支持 LOCAL_DOMAIN WEB_DOMAIN 两个选项。

配置 Mastodon

编辑 .env.production,进行如下修改:

  1. __不要__修改 LOCAL_DOMAIN
  2. 添加 WEB_DOMAIN 配置,设置为一个二级域名,比如 mastodon.example.com

配置 mastodon.example.com

参考 Mastodon 文档,为 mastodon.example.com 配置一个 nginx 主机。重启 Mastodon 的 streaming/sidekiq/web 服务,重新载入 nginx 配置,现在 mastodon.example.com 已经可以访问了。

配置 example.com

但是外部实例尝试连接你的账号 yourname@example.com 时,尚不知晓你的地址是 mastodon.example.com,所以我们希望访问 https://example.com/.well-known/host-meta 时能返回 https://mastodon.example.com/.well-known/host-meta 的内容。

example.com 的 nginx 配置中,移除 Mastodon 的配置,仅添加如下规则:

location = /.well-known/host-meta {
       return 301 https://mastodon.example.com$request_uri;
}

重新载入 nginx 即可。

更多配置

以上配置均来自于 felx 的补充文档 Using a different domain name for Mastodon and the users it serves。正如文中所说,尽管通过主域名跳转和 WEB_DOMAIN 配置,能够实现需求,但因为实例版本不一、客户端种类繁杂,难免仍会有奇怪的问题发生。

而且将已经运行了一段时间的 Mastodon 从主域名切换到二级域名,可能会有更明显的问题。

根据官方文档中的 Routes 章节,以及使用经验,建议为 example.com 设置如下规则,增加兼容性:

## mastodon web url
location ~ ^/(about/more|settings|web|pghero|sidekiq|admin|interact|explore|public|@.*|relationships|filters|terms|inert.css){
        rewrite ^(.*) https://$mastodon_host$1 permanent;
}

## mastodon .well-known
location ~ ^/(.well-known/(host-meta|nodeinfo|webfinger|change-password|keybase-proof-config)|nodeinfo) {
        rewrite ^(.*) https://$mastodon_host$1 permanent;
}

## mastodon system resources
location ~ ^/(system|headers|avatars) {
        ## set your mastodon public folder, or just redirect to $mastodon_host
        #rewrite ^(.*) https://$mastodon_host$1 permanent;
        root /home/mastodon/live/public;
}

## mastodon url (possible use post)
location ~ ^/(api/v1|inbox|actor|oauth|auth|users){
        return 308 https://$mastodon_host$request_uri;
}

现在可以用 yourname@example.com 来嘟嘟了。