在同一域名下,将 Discourse 运行在 / 路径,同时将自定义应用运行在 /tickets 路径

大家好,

我正试图确认一种正确的架构,用于在保持 Discourse 位于根目录 (/) 的同时,通过子路径提供自定义应用程序,而无需修改 Discourse 内部。

我想要的结果(最终目标)

https://mydomain.com/         → Discourse
https://mydomain.com/tickets  → 自定义工单系统 (Go + Gin)

要求:

  1. Discourse 必须保持在 /,自定义应用必须位于 /tickets
  2. 相同的域名
  3. 不使用 Discourse 插件

当前环境

  1. OVH VPS (Ubuntu),Discourse 运行在 Docker 中 (/var/discourse)
  2. 自定义 Go 应用运行在同一服务器上的 127.0.0.1:8080
  3. 外部 nginx 安装在宿主机上(不在容器内)

不是想在像 /forum 这样的子文件夹中运行 Discourse。哦,在有人问之前,是的,我尝试过使用 Discourse tickets 插件——但它不能按我想要的方式工作。

您可以使用 nginx 轻松完成此操作,虽然不推荐,但我不知道 discourse 会将 /tickets 路由用于任何其他目的。

感谢您的快速回复!我正在使用 nginx 并且遇到了困难。这是我的配置,但仍然没有成功。

这是在我的 app.yml 文件中

ports:
  - "127.0.0.1:4000:4000"
  #- "80:80" # http
  #- "443:443" # https

/etc/nginx/sites-enabled/filename

server {
    listen 80;
    server_name mydomain.com;

    # ---- Tickets app ----
    location ^~ /tickets {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_redirect off;

        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;

        # Discourse auth headers
        proxy_set_header X-Discourse-Username $http_x_discourse_username;
        proxy_set_header X-Discourse-User-Id $http_x_discourse_user_id;
        proxy_set_header X-Discourse-Groups $http_x_discourse_groups;
    }

    # ---- Discourse ----
    location / {
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_redirect off;

        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;
    }
}

您能确切说明您在哪里遇到困难吗?

2 个赞

我认为那些可能是你最好的说明,尽管是反向操作。你将按照那些说明进行操作,但要“反向”进行。你将让你的外部反向代理将 / 指向 Discourse,将 /tickets 指向你的应用程序。

@pfaffman 所以我的理解是:重用概念,而不是配置——在前面放置一个外部反向代理来路由:

  • / → Discourse

  • /tickets → 我的自定义应用

Discourse 完全不知道 /tickets 的存在。
所以是遵循这个指南,对吗:Serve Discourse from a subfolder (path prefix) instead of a subdomain

1 个赞

我认为外部 nginx 是最简单的方法。可以创建一个模板让内部的 nginx 来做这件事,但这更复杂,而且我认为收益不大。

是的,但你除了移除 ssl/let’s encrypt 模板和可能使用一个套接字(socket)之外,不需要对 discourse 容器做任何更改。(所以,实际上,该主题中没什么能提供太大帮助的。)

我让它工作了!

感谢你们两位的回复!

我添加到 Discourse 标题中的“Tickets”链接也能正常工作,当它被设置为“blank”(空白)而不是“self”时,因为 /tickets 会被当作一个 Discourse 路由来处理并尝试仅切换 react 视图。空白会强制进行完整的页面重新加载。