如何使用动态重定向?

我正在从 Vanilla 迁移到 Discourse,我们决定重新开始,而不是导入过去 8 年的主题。目前的网站是 forums.29th.org,所以我打算在 Discourse 完全运行起来后,将 forums.29th.org 分配给 Discourse,而把 Vanilla 迁移到另一个域名,比如 vanilla.29th.org(实际上,由于我们现在有多个旧论坛,我正在努力想出一个合适的 URL 命名规范!)

因此,我希望将匹配 Vanilla URL 模式的请求重定向到另一个域名。通过 nginx 规则实现这一点非常简单,但:(a) 我想确认是否可以使用 Discourse 的内置功能(例如“固定链接”)来实现;(b) 如果不行,我该如何正确编辑 nginx 配置(如果能对其进行版本控制那就太好了)。

作为背景,Vanilla 的主题 URL 格式如下:

/discussion/42206/example-topic#latest

谢谢!

我会使用一条 nginx 规则将 /discussion 重定向到新/旧域名。(并且我会导入旧数据,不过,这就是我谋生的方式。)

@pfaffman 谢谢——但我该如何找到编辑 nginx 规则的位置?我需要运行 launcher enter app 然后修改 /etc/nginx/nginx.conf 文件吗?考虑到这些是临时容器,我本以为应该编辑某个版本控制的内容——这可行吗?

您可以在 app.yml 中添加内容以修改 nginx 配置(或运行外部配置)。我不太确定哪里最适合向您发送这些信息。以下是为其他目的修改 nginx 配置的一个示例:

  after_ssl:
   # 不要将所有主机重定向回主域名
    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: /if \\(\\$http_host[^\\}]*\\}/m
        to: ""
    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: /return 301.*$/
        to: "return 301 https://$host$request_uri;"

完美——这正是我想看到的。谢谢!这类信息是否有文档可供查阅?

1 个赞

供其他访问此处的用户参考,我是通过 SSH 登录服务器,进入 /var/discourse 目录,用 vim 打开 containers/app.yml,然后滚动到 hooks 部分来实现的。我添加了以下内容:

hooks: # 这一行应该已经存在
  after_ssl:
    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: "location @discourse {"
        to: |
          location /discussion/ {
            return 301 https://vanilla.29th.org$request_uri;
          }

          location @discourse {
  after_code: # 这一行应该已经存在
1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.