mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-01 15:42:25 -05:00
[docs] add zh docs (#3507)
* [docs] add zh docs * [docs] add lang dropdown * [docs] update mkdocs zh config * [docs] migrate assets * [docs] update overrides dir in mkdocs zh config * [docs] exclude locales director in main mkdocs config * [docs] rename assets to public to avoid conflicting with template * [docs] extra_css change followup * [docs] add theme.palette.toggle.icon back into mkdocs zh config * [docs] fix zh readme reference + migrate language-specific repo markdown to docs * [docs] translate remaining repo docs + update reference * [docs] update zh index.md reference * [docs/zh] wording alignment
This commit is contained in:
parent
e953d80dff
commit
38a08cd25a
139 changed files with 20407 additions and 24 deletions
261
docs/locales/zh/getting_started/reverse_proxy/apache-httpd.md
Normal file
261
docs/locales/zh/getting_started/reverse_proxy/apache-httpd.md
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
# Apache HTTP 服务器
|
||||
|
||||
要将 Apache 用作 GoToSocial 的反向代理,你需要在服务器上安装它。如果你还希望 Apache 处理 TLS,就需要[配置 TLS 证书](../../advanced/certificates.md)。
|
||||
|
||||
Apache 已被[打包用于许多发行版](https://repology.org/project/apache/versions)。你很可能可以使用发行版的包管理器来安装它。你还可以使用发布到 Docker Hub 的[官方 Apache 镜像](https://hub.docker.com/_/httpd)通过容器运行 Apache。
|
||||
|
||||
本指南还将展示如何使用 certbot 来配置 TLS 证书。它同样被[打包在许多发行版](https://repology.org/project/certbot/versions)中,但许多发行版往往附带较旧版本的 certbot。如果遇到问题,可以考虑使用[容器镜像](https://hub.docker.com/r/certbot/certbot)。
|
||||
|
||||
## 配置 GoToSocial
|
||||
|
||||
我们将让 Apache 处理 LetsEncrypt 证书,所以你需要在 GoToSocial 配置中关闭内置的 LetsEncrypt 支持。
|
||||
|
||||
首先在文本编辑器中打开文件:
|
||||
|
||||
```bash
|
||||
sudoedit /gotosocial/config.yaml
|
||||
```
|
||||
|
||||
然后设置 `letsencrypt-enabled: false`。
|
||||
|
||||
如果反向代理将在同一台机器上运行,请将 `bind-address` 设置为 `"localhost"`,这样 GoToSocial 服务器仅通过环回才可以访问。否则可能会直接连接到 GoToSocial 以绕过你的代理,这是我们不希望的。
|
||||
|
||||
如果 GoToSocial 已经在运行,请重启它。
|
||||
|
||||
```bash
|
||||
sudo systemctl restart gotosocial.service
|
||||
```
|
||||
|
||||
或者,如果你没有配置 systemd 服务,只需手动重启。
|
||||
|
||||
## 设置 Apache
|
||||
|
||||
### 所需的 Apache 模块
|
||||
|
||||
你需要确保安装并启用了多个 Apache 模块。这些模块应该都在你的发行版的 Apache 包中,但可能被拆分成单独的包。
|
||||
|
||||
你可以通过 `apachectl -M` 查看已安装哪些模块。
|
||||
|
||||
你需要加载以下模块:
|
||||
|
||||
* `proxy_http` 来代理 HTTP 请求到 GoToSocial
|
||||
* `ssl` 来处理 SSL/TLS
|
||||
* `headers` 来操作 HTTP 请求和响应头
|
||||
* `rewrite` 来重写 HTTP 请求
|
||||
* `md` 用于 Lets Encrypt,自 2.4.30 开始可用
|
||||
|
||||
在 Debian、Ubuntu 和 openSUSE 中,可以使用 [`a2enmod`](https://manpages.debian.org/bookworm/apache2/a2enmod.8.en.html) 工具加载任何额外的模块。对于 Red Hat/CentOS 系列发行版,你需要在 Apache 配置中添加 [`LoadModule` 指令](https://httpd.apache.org/docs/2.4/mod/mod_so.html#loadmodule)。
|
||||
|
||||
### 使用 mod_md 启用 TLS
|
||||
|
||||
!!! note
|
||||
`mod_md` 自 Apache 2.4.30 开始可用,仍被视为实验性的。实际上,它在实践中表现良好,是最便捷的方法。
|
||||
|
||||
现在我们将配置 Apache HTTP 服务器来处理 GoToSocial 请求。
|
||||
|
||||
首先,我们将在 `/etc/apache2/sites-available` 中为 Apache HTTP 服务器编写配置:
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /etc/apache2/sites-available/
|
||||
sudoedit /etc/apache2/sites-available/example.com.conf
|
||||
```
|
||||
|
||||
在上述 `sudoedit` 命令中,将 `example.com` 替换为你的 GoToSocial 服务器的域名。
|
||||
|
||||
你将创建的文件应如下所示:
|
||||
|
||||
=== "2.4.47+"
|
||||
```apache
|
||||
MDomain example.com auto
|
||||
MDCertificateAgreement accepted
|
||||
|
||||
<VirtualHost *:80 >
|
||||
ServerName example.com
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerName example.com
|
||||
|
||||
SSLEngine On
|
||||
ProxyPreserveHost On
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
ProxyPass / http://127.0.0.1:8080/ upgrade=websocket
|
||||
ProxyPassReverse / http://127.0.0.1:8080/
|
||||
|
||||
RequestHeader set "X-Forwarded-Proto" expr=https
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
=== "旧版本"
|
||||
```apache
|
||||
MDomain example.com auto
|
||||
MDCertificateAgreement accepted
|
||||
|
||||
<VirtualHost *:80 >
|
||||
ServerName example.com
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerName example.com
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} websocket [NC]
|
||||
RewriteCond %{HTTP:Connection} upgrade [NC]
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
RewriteRule ^/?(.*) "ws://127.0.0.1:8080/$1" [P,L]
|
||||
|
||||
SSLEngine On
|
||||
ProxyPreserveHost On
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
ProxyPass / http://127.0.0.1:8080/
|
||||
ProxyPassReverse / http://127.0.0.1:8080/
|
||||
|
||||
RequestHeader set "X-Forwarded-Proto" expr=https
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
同样,将上述配置文件中的 `example.com` 替换为你的 GoToSocial 服务器的域名。如果你的域名是 `gotosocial.example.com`,那么用 `gotosocial.example.com` 作为正确的值。
|
||||
|
||||
你还应该将 `http://127.0.0.1:8080` 更改为 GoToSocial 服务器的正确地址和端口(如果它不在 `127.0.0.1:8080` 上)。例如,如果你在另一台机器上以 `192.168.178.69` 的本地 IP 运行 GoToSocial,并且端口为 `8080`,那么 `http://192.168.178.69:8080/` 就是正确的值。
|
||||
|
||||
需要 `Rewrite*` 指令以确保 Websocket 流连接正常工作。有关更多信息,请参阅 [websocket](./websocket.md) 文档。
|
||||
|
||||
`ProxyPreserveHost On` 是必要的:它保证代理和 GoToSocial 使用相同的服务器名称。否则,GoToSocial 会构建错误的身份验证标头,所有联合尝试将被拒绝并返回 401 未授权。
|
||||
|
||||
默认情况下,Apache 会在转发的请求中设置 `X-Forwarded-For`。为了使这个设置和限速工作,设置 `trusted-proxies` 配置变量。请参阅[限速](../../api/ratelimiting.md)和[基础配置](../../configuration/general.md)文档。
|
||||
|
||||
保存并关闭配置文件。
|
||||
|
||||
现在,我们需要将刚创建的文件链接到 Apache HTTP 服务器读取已激活站点配置的文件夹中。
|
||||
|
||||
```bash
|
||||
sudo mkdir /etc/apache2/sites-enabled
|
||||
sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/
|
||||
```
|
||||
|
||||
在上述 `ln` 命令中,将 `example.com` 替换为你的 GoToSocial 服务器的域名。
|
||||
|
||||
现在检查配置错误。
|
||||
|
||||
```bash
|
||||
sudo apachectl -t
|
||||
```
|
||||
|
||||
如果一切正常,你应该看到以下输出:
|
||||
|
||||
```text
|
||||
Syntax OK
|
||||
```
|
||||
|
||||
一切正常?太好了!然后重启 Apache HTTP 服务器以加载新的配置文件。
|
||||
|
||||
```bash
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
现在,观测日志以查看新 LetsEncrypt 证书何时送达(`tail -F /var/log/apache2/error.log`),然后使用上述 `systemctl restart` 命令再次重载 Apache。之后,你应该就可以开始了!
|
||||
|
||||
每当 `mod_md` 获取新证书时,需要重启(或重载)Apache HTTP 服务器;请参阅该模块的文档以了解[更多信息](https://github.com/icing/mod_md#how-to-manage-server-reloads)。
|
||||
|
||||
根据你使用的 Apache HTTP 服务器版本,可能会看到以下错误:`error (specific information not available): acme problem urn:ietf:params:acme:error:invalidEmail: Error creating new account :: contact email "webmaster@localhost" has invalid domain : Domain name needs at least one dot`
|
||||
|
||||
如果发生这种情况,你需要进行以下操作之一(或全部):
|
||||
|
||||
1. 更新 `/etc/apache2/sites-enabled/000-default.conf` 并将 `ServerAdmin` 值更改为有效的电子邮件地址(然后重载 Apache HTTP 服务器)。
|
||||
2. 在 `/etc/apache2/sites-available/example.com.conf` 的 `MDomain` 行下添加行 `MDContactEmail your.email.address@whatever.com`,将 `your.email.address@whatever.com` 替换为有效的电子邮件地址,并将 `example.com` 替换为你的 GoToSocial 域名。
|
||||
|
||||
### 使用外部管理证书启用 TLS
|
||||
|
||||
!!! note
|
||||
我们有关于如何[配置 TLS 证书](../../advanced/certificates.md)的额外文档,其中还提供了不同发行版的其他内容和教程链接,可能值得查看。
|
||||
|
||||
如果你更喜欢手动设置或使用不同服务(如 Certbot)来管理 SSL,可以为你的 Apache HTTP 服务器使用更简单的设置。
|
||||
|
||||
首先,我们将在 `/etc/apache2/sites-available` 中为 Apache HTTP 服务器编写配置:
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /etc/apache2/sites-available/
|
||||
sudoedit /etc/apache2/sites-available/example.com.conf
|
||||
```
|
||||
|
||||
在上述 `sudoedit` 命令中,将 `example.com` 替换为你的 GoToSocial 服务器的域名。
|
||||
|
||||
你将创建的文件最初应如下所示,针对 80(必需)和 443 端口(可选):
|
||||
|
||||
=== "2.4.47+"
|
||||
```apache
|
||||
<VirtualHost *:80>
|
||||
ServerName example.com
|
||||
|
||||
ProxyPreserveHost On
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
ProxyPass / http://127.0.0.1:8080/ upgrade=websocket
|
||||
ProxyPassReverse / http://127.0.0.1:8080/
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
=== "旧版本"
|
||||
```apache
|
||||
<VirtualHost *:80>
|
||||
ServerName example.com
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} websocket [NC]
|
||||
RewriteCond %{HTTP:Connection} upgrade [NC]
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
RewriteRule ^/?(.*) "ws://127.0.0.1:8080/$1" [P,L]
|
||||
|
||||
ProxyPreserveHost On
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
ProxyPass / http://127.0.0.1:8080/
|
||||
ProxyPassReverse / http://127.0.0.1:8080/
|
||||
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
同样,将上述配置文件中的 `example.com` 替换为你的 GoToSocial 服务器的域名。如果你的域名是 `gotosocial.example.com`,那么用 `gotosocial.example.com` 作为正确的值。
|
||||
|
||||
你还应该将 `http://127.0.0.1:8080` 更改为 GoToSocial 服务器的正确地址和端口(如果它不在 `127.0.0.1:8080` 上)。例如,如果你在另一台机器上以 `192.168.178.69` 的本地 IP 运行 GoToSocial,并且端口为 `8080`,那么 `http://192.168.178.69:8080/` 就是正确的值。
|
||||
|
||||
需要 `Rewrite*` 指令以确保 Websocket 流连接正常工作。有关更多信息,请参阅 [websocket](websocket.md) 文档。
|
||||
|
||||
`ProxyPreserveHost On` 是必需的:它保证代理和 GoToSocial 使用相同的服务器名称。否则,GoToSocial 会构建错误的身份验证头,所有联合尝试将被拒绝并返回 401 未授权。
|
||||
|
||||
在443端口提供初始设置以供外部工具进行附加管理时,你可以使用服务器提供的默认证书,你可以在 `/etc/apache2/sites-available/` 的 `default-ssl.conf` 文件中找到引用。
|
||||
|
||||
保存并关闭配置文件。
|
||||
|
||||
现在,我们需要将刚创建的文件链接到 Apache HTTP 服务器读取已激活站点配置的文件夹中。
|
||||
|
||||
```bash
|
||||
sudo mkdir /etc/apache2/sites-enabled
|
||||
sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/
|
||||
```
|
||||
|
||||
在上述 `ln` 命令中,将 `example.com` 替换为你的 GoToSocial 服务器的域名。
|
||||
|
||||
现在检查配置错误。
|
||||
|
||||
```bash
|
||||
sudo apachectl -t
|
||||
```
|
||||
|
||||
如果一切正常,你应该看到以下输出:
|
||||
|
||||
```text
|
||||
Syntax OK
|
||||
```
|
||||
|
||||
一切正常?太好了!然后重启 Apache HTTP 服务器以加载新的配置文件。
|
||||
|
||||
```bash
|
||||
sudo systemctl restart apache2
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
如果无法在浏览器中连接到站点,则反向代理设置不起作用。比较 Apache 日志文件(`tail -F /var/log/apache2/access.log`)和 GoToSocial 日志文件。发出的请求必须在两个地方中都显示出来。仔细检查 `ProxyPass` 设置。
|
||||
|
||||
如果可以连接,但贴文未能联合且账户无法从其他地方找到,请检查日志。如果你看到尝试读取你的个人资料(比如 `level=INFO … method=GET statusCode=401 path=/users/your_username msg="Unauthorized: …"`)或向你的收件箱发送贴文的信息(比如 `level=INFO … method=POST statusCode=404 path=/your_username/inbox msg="Not Found: …"`),则联合已被中断。仔细检查 `ProxyPreserveHost` 设置。
|
||||
|
||||
如果可以连接但无法在 Mastodon 客户端应用中授权账户,请确保从正确的域名启动登录。当使用[分域](../../advanced/host-account-domain.md)设置时,必须从 `host` 域启动登录,而不是 `account-domain`。GoToSocial 设置了 `Content-Security-Policy` 头,以抵御 XSS 和数据注入攻击。该头应保持不变,确保你的反向代理没有修改、覆盖或取消设置它。
|
||||
110
docs/locales/zh/getting_started/reverse_proxy/caddy.md
Normal file
110
docs/locales/zh/getting_started/reverse_proxy/caddy.md
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
# Caddy 2
|
||||
|
||||
## 要求
|
||||
|
||||
在此指南中,你需要使用 [Caddy 2](https://caddyserver.com/),无需其他依赖。Caddy 管理 Lets Encrypt 证书及其续订。
|
||||
|
||||
Caddy 可以通过大多数流行的包管理器获取,或者你可以获取一个静态二进制文件。最新的安装指南请参考[他们的手册](https://caddyserver.com/docs/install)。
|
||||
|
||||
### Debian, Ubuntu, Raspbian
|
||||
|
||||
```bash
|
||||
# 为其自定义仓库添加密钥环。
|
||||
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
|
||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
|
||||
|
||||
# 更新软件包并安装
|
||||
sudo apt update
|
||||
sudo apt install caddy
|
||||
```
|
||||
|
||||
### Fedora, Redhat, Centos
|
||||
|
||||
```bash
|
||||
dnf install 'dnf-command(copr)'
|
||||
dnf copr enable @caddy/caddy
|
||||
dnf install caddy
|
||||
```
|
||||
|
||||
### Arch
|
||||
|
||||
```bash
|
||||
pacman -Syu caddy
|
||||
```
|
||||
|
||||
### FreeBSD
|
||||
|
||||
```bash
|
||||
sudo pkg install caddy
|
||||
```
|
||||
|
||||
## 配置 GoToSocial
|
||||
|
||||
如果 GoToSocial 已经在运行,先停止它。
|
||||
|
||||
```bash
|
||||
sudo systemctl stop gotosocial
|
||||
```
|
||||
|
||||
在你的 GoToSocial 配置中,通过将 `letsencrypt-enabled` 设置为 `false` 来关闭 Lets Encrypt。
|
||||
|
||||
如果你之前在 443 端口运行 GoToSocial,需将 `port` 值改回默认的 `8080`。
|
||||
|
||||
如果反向代理将在同一台机器上运行,将 `bind-address` 设置为 `"localhost"`,这样 GoToSocial 服务器只能通过回环地址访问。否则可能会有人直接连接到 GoToSocial 以绕过你的代理,这是不安全的。
|
||||
|
||||
## 设置 Caddy
|
||||
|
||||
我们将配置 Caddy 2 来在主域名 example.org 上使用 GoToSocial。由于 Caddy 负责获取 Lets Encrypt 证书,我们只需正确配置它一次。
|
||||
|
||||
在最简单的使用场景中,Caddy 默认使用名为 Caddyfile 的文件。它可以在更改时重新加载,或者通过 HTTP API 配置以实现零停机,但这超出了我们当前的讨论范围。
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /etc/caddy
|
||||
sudo vim /etc/caddy/Caddyfile
|
||||
```
|
||||
|
||||
在编辑上述文件时,你应将 'example.org' 替换为你的域名。你的域名应在当前配置中出现两次。如果你为 GoToSocial 选择了端口号 8080 以外的端口,请在反向代理行中更改端口号以匹配它。
|
||||
|
||||
你即将创建的文件应如下所示:
|
||||
|
||||
```Caddyfile
|
||||
example.org {
|
||||
# 可选,但推荐,使用适当的协议压缩流量
|
||||
encode zstd gzip
|
||||
|
||||
# 实际的代理配置为端口 8080(除非你选择了其他端口号)
|
||||
reverse_proxy * http://127.0.0.1:8080 {
|
||||
# 立即刷新,以防止缓冲响应给客户端
|
||||
flush_interval -1
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
默认情况下,caddy 在转发请求中设置 `X-Forwarded-For`。为了使其与速率限制配合使用,请设置 `trusted-proxies` 配置变量。详见[速率限制](../../api/ratelimiting.md)和[通用配置](../../configuration/general.md)文档。
|
||||
|
||||
有关进阶配置,请查看 Caddy 文档中的[反向代理指令](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy)。
|
||||
|
||||
现在检查配置错误。
|
||||
|
||||
```bash
|
||||
sudo caddy validate
|
||||
```
|
||||
|
||||
如果一切正常,你将看到一些信息行作为输出。除非前面标有 *[err]* 的行,否则你就准备好了。
|
||||
|
||||
一切正常吗?太好了!然后重启 caddy 以加载你的新配置文件。
|
||||
|
||||
```bash
|
||||
sudo systemctl restart caddy
|
||||
```
|
||||
|
||||
如果一切顺利,你现在就可以享受你的 GoToSocial 实例,所以我们将再次启动它。
|
||||
|
||||
```bash
|
||||
sudo systemctl start gotosocial
|
||||
```
|
||||
|
||||
## 结果
|
||||
|
||||
你现在应该能够在浏览器中打开你的实例的启动页面,并会看到它在 HTTPS 下运行!
|
||||
43
docs/locales/zh/getting_started/reverse_proxy/index.md
Normal file
43
docs/locales/zh/getting_started/reverse_proxy/index.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 反向代理
|
||||
|
||||
GoToSocial 可以直接暴露到互联网上。不过,许多人更愿意使用反向代理来处理外部连接。这也可以使你对 TLS 配置有更大的控制权,并启用一些更复杂的场景,比如资源缓存。
|
||||
|
||||
## 一般步骤
|
||||
|
||||
要使用反向代理,通常需要做以下几件事:
|
||||
|
||||
* 配置某种方式获取主机域名的 TLS 证书
|
||||
* 将 GoToSocial 绑定到一个本地 IP 而不是公网 IP,并使用非特权端口。调整 `bind-address` 和 `port` 配置选项
|
||||
* 如果你使用了 Lets Encrypt,在 GoToSocial 中禁用它。将 `letsencrypt-enabled` 设置为 `false`
|
||||
* 配置反向代理以处理 TLS 并将请求代理到 GoToSocial
|
||||
|
||||
!!! warning
|
||||
不要更改 `host` 配置选项的值。这必须保持为其他实例在互联网上看到的实际域名。相反,改变 `bind-address` 并更新 `port` 和 `trusted-proxies`。
|
||||
|
||||
### 容器
|
||||
|
||||
当你使用我们的[Docker Compose 示例指南](../installation/container.md)部署 GoToSocial 时,它默认绑定到端口 `443`,假设你希望直接将其暴露到互联网上。要在反向代理后运行它,你需要更改这些设置。
|
||||
|
||||
在 Compose 文件中:
|
||||
|
||||
* 注释掉 `ports` 定义中的 `- "443:8080"` 行
|
||||
* 如果你启用了 Lets Encrypt 支持:
|
||||
* 注释掉 `ports` 定义中的 `- "80:80"` 行
|
||||
* 将 `GTS_LETSENCRYPT_ENABLED` 设置回 `"false"` 或注释掉
|
||||
* 改为取消注释 `- "127.0.0.1:8080:8080"` 行
|
||||
|
||||
这将导致 Docker 仅在 `127.0.0.1` 的端口 `8080` 上转发连接到容器,有效地将其与外界隔离。你现在可以指示反向代理将请求发送到那里。
|
||||
|
||||
## 指南
|
||||
|
||||
我们为以下服务器提供了指南:
|
||||
|
||||
* [nginx](nginx.md)
|
||||
* [Apache httpd](apache-httpd.md)
|
||||
* [Caddy 2](caddy.md)
|
||||
|
||||
## WebSockets
|
||||
|
||||
使用反向代理时,必须特别注意允许 WebSockets 正常工作。因为许多客户端应用程序使用 WebSockets 来流式传输你的时间线。WebSockets 不用于联合。
|
||||
|
||||
请确保阅读 [WebSocket](websocket.md) 文档,并相应地配置你的反向代理。
|
||||
186
docs/locales/zh/getting_started/reverse_proxy/nginx.md
Normal file
186
docs/locales/zh/getting_started/reverse_proxy/nginx.md
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
# NGINX
|
||||
|
||||
要使用 NGINX 作为 GoToSocial 的反向代理,你需要在服务器上安装它。如果你打算让 NGINX 处理 TLS,你还需要[配置 TLS 证书](../../advanced/certificates.md)。
|
||||
|
||||
!!! tip
|
||||
通过在 `server` 块中包含 `http2 on;` 来启用 NGINX 的 HTTP/2。这样可以加快客户端的体验。请参阅 [ngx_http_v2_module 文档](https://nginx.org/en/docs/http/ngx_http_v2_module.html#example)。
|
||||
|
||||
NGINX 已为[多个发行版打包](https://repology.org/project/nginx/versions)。你很可能可以使用发行版的包管理器来安装它。你也可以使用 Docker Hub 上发布的[官方 NGINX 镜像](https://hub.docker.com/_/nginx)通过容器运行 NGINX。
|
||||
|
||||
在本指南中,我们还将展示如何使用 certbot 配置 TLS 证书。它也在[许多发行版中打包](https://repology.org/project/certbot/versions),但许多发行版往往提供的 certbot 版本较旧。如果遇到问题,可以考虑使用[容器镜像](https://hub.docker.com/r/certbot/certbot)。
|
||||
|
||||
## 配置 GoToSocial
|
||||
|
||||
如果 GoToSocial 已在运行,先停止它。
|
||||
|
||||
```bash
|
||||
sudo systemctl stop gotosocial
|
||||
```
|
||||
|
||||
或者如果你没有 systemd 服务,只需手动停止它。
|
||||
|
||||
这样调整你的 GoToSocial 配置:
|
||||
|
||||
```yaml
|
||||
letsencrypt-enabled: false
|
||||
port: 8080
|
||||
bind-address: 127.0.0.1
|
||||
```
|
||||
|
||||
第一个设置禁用了内置的 TLS 证书配置。由于 NGINX 现在将处理这些流量,GoToSocial 不再需要绑定到 443 端口或任何特权端口。
|
||||
|
||||
通过将 `bind-address` 设置为 `127.0.0.1`,GoToSocial 将不再能直接从外部访问。如果你的 NGINX 和 GoToSocial 实例不在同一台服务器上,你需要绑定一个允许你的反向代理访问你的 GoToSocial 实例的 IP 地址。绑定到私有 IP 地址可以确保只有通过 NGINX 才能访问 GoToSocial。
|
||||
|
||||
## 设置 NGINX
|
||||
|
||||
我们首先设置 NGINX 为 GoToSocial 提供不安全的 http 服务,然后使用 Certbot 自动升级为 https 服务。
|
||||
|
||||
请勿在此完成之前尝试使用,否则你将有泄露密码的风险,或破坏联合。
|
||||
|
||||
首先,我们将为 NGINX 编写一个配置文件,并将其放入 `/etc/nginx/sites-available` 中。
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /etc/nginx/sites-available
|
||||
sudoedit /etc/nginx/sites-available/yourgotosocial.url.conf
|
||||
```
|
||||
|
||||
在上述命令中,将 `yourgotosocial.url` 替换为你的实际 GoToSocial 主机值。所以如果你的 `host` 设置为 `example.org`,那么文件应该命名为 `/etc/nginx/sites-available/example.org.conf`
|
||||
|
||||
你要创建的文件应该如下所示:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name example.org;
|
||||
location / {
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
proxy_pass http://127.0.0.1:8080;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
client_max_body_size 40M;
|
||||
}
|
||||
```
|
||||
|
||||
将 `proxy_pass` 改为你实际运行 GoToSocial 的 IP 和端口(如果不是 `127.0.0.1:8080`),并将 `server_name` 改为你自己的域名。
|
||||
|
||||
如果你的域名是 `example.org`,那么 `server_name example.org;` 就是正确的值。
|
||||
|
||||
如果你在另一台本地 IP 为 192.168.178.69 的机器上运行 GoToSocial,并在端口 8080 上,那么 `proxy_pass http://192.168.178.69:8080;` 就是正确的值。
|
||||
|
||||
**注意**:如果你的服务器不支持 IPv6,可以删除 `listen [::]:80;` 这一行。
|
||||
|
||||
**注意**:`proxy_set_header Host $host;` 必不可少。它确保代理和 GoToSocial 使用相同的服务器名称。如果没有,GoToSocial 将构建错误的身份验证标头,导致所有的联合尝试以 401 被拒绝。
|
||||
|
||||
**注意**:`Connection` 和 `Upgrade` 头用于 WebSocket 连接。请参阅 [WebSocket 文档](websocket.md)。
|
||||
|
||||
**注意**:本例中 `client_max_body_size` 设置为 40M,这是 GoToSocial 的默认视频上传大小。根据需要你可以将此值设置得更大或更小。nginx 的默认值仅为 1M,太小了。
|
||||
|
||||
**注意**:为了使 `X-Forwarded-For` 和限流生效,请设置 `trusted-proxies` 配置变量。请参阅[限流](../../api/ratelimiting.md)和[通用配置](../../configuration/general.md)文档。
|
||||
|
||||
接下来我们需要将刚创建的文件链接到 nginx 从中读取活动站点配置的文件夹中。
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /etc/nginx/sites-enabled
|
||||
sudo ln -s /etc/nginx/sites-available/yourgotosocial.url.conf /etc/nginx/sites-enabled/
|
||||
```
|
||||
|
||||
再次将 `yourgotosocial.url` 替换为你的实际 GoToSocial 主机值。
|
||||
|
||||
现在检查配置错误。
|
||||
|
||||
```bash
|
||||
sudo nginx -t
|
||||
```
|
||||
|
||||
如果一切正常,你应该会看到以下输出:
|
||||
|
||||
```text
|
||||
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
|
||||
nginx: configuration file /etc/nginx/nginx.conf test is successful
|
||||
```
|
||||
|
||||
一切正常吗?太好了!然后重启 nginx 以加载新的配置文件。
|
||||
|
||||
```bash
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
||||
## 设置 TLS
|
||||
|
||||
!!! warning
|
||||
我们有关于如何[配置 TLS 证书](../../advanced/certificates.md)的附加文档,还提供了有关不同发行版的附加内容和教程链接,值得一看。
|
||||
|
||||
你现在可以运行 certbot,它将引导你完成启用 https 的步骤。
|
||||
|
||||
```bash
|
||||
sudo certbot --nginx
|
||||
```
|
||||
|
||||
完成后,它应该自动编辑你的配置文件以启用 https。
|
||||
|
||||
最后再次重新加载 NGINX:
|
||||
|
||||
```bash
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
||||
现在重新启动 GoToSocial:
|
||||
|
||||
```bash
|
||||
sudo systemctl start gotosocial
|
||||
```
|
||||
|
||||
## 安全加固
|
||||
|
||||
如果你想通过进阶配置选项加强 NGINX 部署,网上有很多指南([例如这个](https://beaglesecurity.com/blog/article/nginx-server-security.html))。请尝试找到最新的指南。Mozilla 还[在此处](https://ssl-config.mozilla.org/)发布了最佳实践 SSL 配置。
|
||||
|
||||
## 结果
|
||||
|
||||
你现在应该可以在浏览器中打开实例的启动页面,并看到它运行在 https 下!
|
||||
|
||||
如果你再次打开 NGINX 配置,你会发现 Certbot 添加了一些额外的行。
|
||||
|
||||
!!! warning
|
||||
根据你设置 Certbot 时选择的选项,以及使用的 NGINX 版本,可能会有所不同。
|
||||
|
||||
```nginx
|
||||
server {
|
||||
server_name example.org;
|
||||
location / {
|
||||
# 设置为 127.0.0.1 而不是 localhost 以解决 https://stackoverflow.com/a/52550758
|
||||
proxy_pass http://127.0.0.1:8080;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
client_max_body_size 40M;
|
||||
|
||||
listen [::]:443 ssl; # 由 Certbot 管理
|
||||
listen 443 ssl; # 由 Certbot 管理
|
||||
http2 on; # 由 Certbot 管理
|
||||
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; # 由 Certbot 管理
|
||||
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; # 由 Certbot 管理
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf; # 由 Certbot 管理
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # 由 Certbot 管理
|
||||
}
|
||||
|
||||
server {
|
||||
if ($host = example.org) {
|
||||
return 301 https://$host$request_uri;
|
||||
} # 由 Certbot 管理
|
||||
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name example.org;
|
||||
return 404; # 由 Certbot 管理
|
||||
}
|
||||
```
|
||||
|
||||
关于 nginx 的其他配置选项(包括静态资源服务和缓存),请参阅文档的[进阶配置部分](../../advanced/index.md)。
|
||||
43
docs/locales/zh/getting_started/reverse_proxy/websocket.md
Normal file
43
docs/locales/zh/getting_started/reverse_proxy/websocket.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# WebSocket
|
||||
|
||||
GoToSocial 使用安全的 [WebSocket 协议](https://en.wikipedia.org/wiki/WebSocket)(即 `wss`)来通过客户端应用程序(如 Semaphore)实现贴文和通知的实时更新。
|
||||
|
||||
为了使用此功能,你需要确保配置 GoToSocial 所在的代理允许 WebSocket 连接通过。
|
||||
|
||||
WebSocket 端点位于 `wss://example.org/api/v1/streaming`,其中 `example.org` 是你的 GoToSocial 实例的域名。
|
||||
|
||||
WebSocket 端点使用在[通用配置](../../configuration/general.md)的 `port` 部分中配置的相同端口。
|
||||
|
||||
典型的 WebSocket **请求**头,如 Pinafore 所发送的如下所示:
|
||||
|
||||
```text
|
||||
Host: example.org
|
||||
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0
|
||||
Accept: */*
|
||||
Accept-Language: en-US,en;q=0.5
|
||||
Accept-Encoding: gzip, deflate, br
|
||||
Sec-WebSocket-Version: 13
|
||||
Origin: https://pinafore.social
|
||||
Sec-WebSocket-Protocol: null
|
||||
Sec-WebSocket-Extensions: permessage-deflate
|
||||
Sec-WebSocket-Key: YWFhYWFhYm9vYmllcwo=
|
||||
DNT: 1
|
||||
Connection: keep-alive, Upgrade
|
||||
Sec-Fetch-Dest: websocket
|
||||
Sec-Fetch-Mode: websocket
|
||||
Sec-Fetch-Site: cross-site
|
||||
Pragma: no-cache
|
||||
Cache-Control: no-cache
|
||||
Upgrade: websocket
|
||||
```
|
||||
|
||||
典型的 WebSocket **响应**头,如 GoToSocial 返回的如下所示:
|
||||
|
||||
```text
|
||||
HTTP/1.1 101 Switching Protocols
|
||||
Upgrade: websocket
|
||||
Connection: Upgrade
|
||||
Sec-WebSocket-Accept: WVdGaFlXRmhZbTl2WW1sbGN3bz0K
|
||||
```
|
||||
|
||||
无论你的设置如何,你都需要确保这些头在你的反向代理中被允许,这可能需要根据所使用的具体反向代理进行额外配置。
|
||||
Loading…
Add table
Add a link
Reference in a new issue