【问题标题】:Ratchet websocket SSL棘轮websocket SSL
【发布时间】:2016-07-29 07:58:52
【问题描述】:

我在我的服务器上使用 Ratchet websocket。它在没有 SSL 的情况下运行良好,但我需要让它与 SSL 一起使用。

我读过这个stackoverflow post。不幸的是,我的 PAAS 支持不使用 httpd.conf。他们建议我直接在 .htaccess 中添加 ProxyPass。

关于在 httpd.conf 文件中添加以下行然后在这里我 想通知我们没有在服务器上使用 httpd 作为 服务器是基于 Debian 的,我们使用的是 Apache Web 服务器。我相信 您可以在 htaccess 文件中使用同一行,或者如果 您可以就此咨询开发者。

# ProxyPass for Ratchet with SSL
ProxyPass /wss2/ ws://127.198.132.141:8000/

# Preventing the app from being indexed
Header set X-Robots-Tag "noindex, nofollow"

# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    [...]

不幸的是,添加 ProxyPass /wss2/ws://127.198.132.141:8000/ 会导致服务器崩溃,就好像 .htaccess 不正确一样。

您有任何解决方案或提示吗?

更新:

据我了解,我们不能在 .htaccess 中使用 ProxyPass,它只能用于服务器配置或虚拟主机配置。

我试图向支持人员解释,但他们似乎不明白。

所以显然禁止在 .htaccess 中使用 ProxyPass。

"ProxyPass 和 ProxyPassReverse 仅在服务器中可用 配置和虚拟主机上下文。”

因此,如果您无法在服务器配置中添加此行,是否可以 在虚拟主机上下文中添加?

他们的回答:

我再次查看了服务器级别的所有设置 包括用于制作 Ratchet 的 Apache 模块和防火墙规则 能够在服务器上运行的 websockets 也是我们拥有的规则 在防火墙中添加表示所有来自外部的流量 允许在端口 8000 上,我相信这应该足以 允许 websocket 的外部连接。

到目前为止,您似乎正在尝试使用 不同的端口(在 https 的情况下)。正如我们已经审查了服务器 设置和配置,一切似乎都很好。

如果您能让开发人员参与进来,我们将不胜感激 这个过程,所以他可以更好地指导你,因为他知道代码级别 事情好多了。

现在尝试连接 wss 会抛出:

与“wss://127.198.132.141/wss2/”的 WebSocket 连接失败: WebSocket 打开握手被取消

虽然将 http 与 ws 一起使用效果很好。

【问题讨论】:

  • 你解决了吗?我有同样的问题
  • 嗨,很遗憾,因为我无法在主机上进行太多配置。我现在不得不停止使用 SSL。我仍然有兴趣找到解决方案;)。
  • 我修复了使用端口 8888。我尝试使用 8080 没有成功。我也写了一个回答,希望对你有帮助。
  • 谢谢,只要端口不被服务器使用,确实是一种解决方案。不幸的是,由于我使用的是 PAAS 解决方案,这些端口已经用于他们的一些服务。没关系,我会验证你的答案;)。

标签: apache .htaccess ssl websocket ratchet


【解决方案1】:

在您的虚拟主机中添加:

ProxyPass /wss2/ ws://yourdomain.xxx:8888/ (尝试使用端口 8888)

别忘了重启apache服务

虚拟主机示例:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

SSLCertificateFile /etc/letsencrypt/live/yourdomain.xxx/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.xxx/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName yourdomain.xxx
ProxyPass /wss2/ ws://yourdomain.xxx:8888/
</VirtualHost>
</IfModule>

在这里您可以找到完整的工作示例 https://github.com/ratchetphp/Ratchet/issues/100

【讨论】:

    猜你喜欢
    • 2013-06-03
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多