【问题标题】:How to setup Ratchet Websocket server for production for Symfony 6 app on platform.sh如何在 platform.sh 上为 Symfony 6 应用程序的生产设置 Ratchet Websocket 服务器
【发布时间】:2022-11-02 03:44:28
【问题描述】:

我正在尝试在我的 Symfony 6 应用程序上为 platform.sh 上的生产环境设置 Ratchet Websocket 服务器

没有找到有关该主题的任何可靠文档,我有几个问题:

  1. 根据https://docs.platform.sh/define-routes.html#websocket-routes,我必须在.platform/routes.yaml for websocket 中定义路由,但实际上我不知道应该放什么值:
    "https://{default}/ws":  # is that some default route ? Should I set it in my app router too ?
        type: upstream
        upstream: "ws-app:http" # what exactly is ws-app ? Should I have a separated app ?
        cache:
            enabled: false
    

    通过ws://127.0.0.1:8080 知道本地服务器工作正常

    1. 如何在生产中实际启动服务器?我应该在我的部署脚本中添加一些东西吗? 我应该使用RabbitMQ 或类似的东西吗?我需要工人吗?

    谢谢你的帮助!

【问题讨论】:

    标签: symfony websocket production-environment ratchet platform.sh


    【解决方案1】:

    请注意,您也在这里发布。希望通过我在这里分享答案,我们可以更多地关注解决方案。

    "https://{default}/ws":
        type: upstream
        upstream: "ws-app:http"
        cache:
            enabled: false
    

    让我们分解一下。

    1. "https://{default}/ws":
      • https:// - 由于您没有配置 http:// 路由,http:// 将自动重定向到 https://
      • {default} 告诉 platform.sh 使用分配给项目的默认域。这很好,特别是如果您还没有附加域。也就是说,您可以键入一个静态值,例如 my-domain.com
      • /ws - 你告诉 Platform.sh 对 /ws (https://{default}/ws) 的任何请求都应该由这个路由定义处理。如果您的开发环境正在向http://localhost/my/websocket 发送websocket 请求,则应将/ws 替换为/my/websocket。使用您的应用配置为使用的路径。
    2. type: upstream - 通常你不会搞砸这个。这只是让 Platform.sh 知道我们将把它定向到您定义的应用程序。
    3. upstream: "ws-app:http"
      • 这与 type: upstream 一起使用,让 Platform.sh 知道您要哪个应用程序回答此请求。
      • ws-app:http - 这是最重要的第一部分 - ws-app。在您的.platform.app.yaml.platform/applications.yaml 中,您将定义一个类似name: appname: my-symfony-app 的值。无论name: 的值是什么,它都应该是该值的第一部分。换句话说,如果您使用name: my-websocket-app,那么在您的 routes.yaml 中您将使用:upstream: "my-websocket-app:http

      一旦这条路由指向您的 websocket 应用程序,您将需要处理下一步,request buffering

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      相关资源
      最近更新 更多