If you have a self-built blog and are planning to or have set up an instance of Mastodon, you will have to face the problem of domain name choice. Assuming your blog is example.com
, should your Mastodon account be [email protected]
or [email protected]
?
For the sake of simplicity and clarity, you will naturally prefer to have the same domain name for your blog and Mastodon. However, Mastodon does not run under a second-level directory. Even if the web part of Mastodon is moved to a second-level domain or directory by means of reverse engineering, there is a high probability that the service, as a decentralized service, will have unknown problems when exchanging data with other instance nodes in the Federation universe.
Fortunately, an important step in inter-federation node communication is access to https://example.com/.well-known/host-meta
, a file whose contents contain URLs for subsequent steps. and Mastodon also supports the LOCAL_DOMAIN
and WEB_DOMAIN
options.
Configuring Mastodon
Edit the .env.production
with the following changes.
- Don't modify
LOCAL_DOMAIN
; - Add WEB_DOMAIN configuration, set to a second-level domain name, such as
mastodon.example.com
.
Configuration mastodon.example.com
Refer to the Mastodon documentation to configure an nginx host for mastodon.example.com
. Restart Mastodon's streaming/sidekiq/web service, reload the nginx configuration, and mastodon.example.com is now accessible.
Configuring example.com
But the external instance trying to connect to your account [email protected]
doesn't yet know that your web address is mastodon.example.com, so we'd like to visit https://example.com/.well-known/host-meta
returns https://mastodon.example.com/.well-known/host-meta
.
In example.com
's nginx configuration, remove Mastodon's configuration and add only the following rules.
location = /.well-known/host-meta {
return 301 https://mastodon.example.com$request_uri;
}
Just reload nginx.
More configurations
The above configurations are from felx's supplemental documentation Using a different domain name for Mastodon and the users it serves. As mentioned in the article, despite the fact that it is possible to achieve the requirements through primary domain hopping and WEB_DOMAIN configuration, there are still strange issues that are inevitable due to the different instance versions and the variety of clients.
And switching Mastodon, which has been running for some time, from a primary domain to a secondary domain may have even more obvious problems.
According to the Routes chapter in the official documentation, as well as experience with it, it is recommended to set the following rules for example.com to increase compatibility.
## 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;
}
You can now toot with [email protected]
.
Webmention
VoteHackerNews
Comment Form
可以请教一下,按照最后的 nginx 写法,安卓客户端登录似乎有些问题,只能以local_domain 登录您那边有这种情况吗?查看 nginx 日志,似乎返回308重定向后客户端会判断为错误,不会发起连接。
我已经不再使用自建 Mastodon 了。当时的确存在这种情况,部分客户端只能以
local_domain
登录。看来,这么多年了,那些客户端还没有修正对 308 的处理。试试把 Mastodon 实例的 nginx.conf 中的 @proxy 配置复制过来,改一改吧写了教程也看不懂系列,tql
哈哈,这是第二步了。第一步搭建教程网上有很多,所以我跳过了