棘轮websocket SSL

时间:2016-07-29 07:58:52

标签: apache .htaccess ssl websocket ratchet

我在服务器上使用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。

     

&#34; ProxyPass和ProxyPassReverse仅在服务器中可用   配置和虚拟主机上下文。&#34;

     

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

他们的回答:

  

我再次审核了服务器级别的所有设置   包括Apache模块和防火墙规则来制作棘轮   websockets能够在服务器上运行我们的规则   在防火墙中添加表示来自外部的所有流量都是   允许在8000端口,我相信哪个应该足够   允许外部连接websocket。

     

截至目前,您似乎正在尝试使用连接   不同的端口(如果是https)。正如我们已经审查了服务器   设置和配置都很好。

     

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

现在尝试连接wss会抛出:

  

WebSocket连接到&#39; wss://127.198.132.141/wss2/'失败:   WebSocket开放握手被取消

使用http和ws工作正常。

1 个答案:

答案 0 :(得分: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

相关问题