首页 文章

棘轮websocket SSL

提问于
浏览
0

我在服务器上使用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不正确一样 .

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

UPDATE :

根据我的理解,我们不能在.htaccess中使用ProxyPass,它应该仅用于服务器配置或虚拟主机配置 .

我试图向支持者解释,但他们似乎并不理解 .

显然禁止在.htaccess中使用ProxyPass . “ProxyPass和ProxyPassReverse仅在服务器配置和虚拟主机上下文中可用 . ”因此,如果您无法在服务器配置中添加此行,是否可以将其添加到虚拟主机上下文中?

他们的回答:

由于我再次审查了服务器级别的所有设置,其中包括Apache模块和防火墙规则,以使Ratchet websockets能够在服务器上运行,我们在Firewall中添加的规则表明允许来自外部的所有流量在端口8000上,我相信哪个应该足以允许websocket的外部连接 . 截至目前,您似乎正在尝试使用不同的端口 Build 连接(在https的情况下) . 正如我们已经审查了服务器设置和配置,所有似乎都很好 . 如果您能够让开发人员参与此过程,那么他将非常感激,因为他可以更好地指导您,因为他更了解代码级别的事情 .

现在尝试连接wss会抛出:

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

虽然使用http与ws工作得很好 .

1 回答

  • 1

    在您的虚拟主机中添加:

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

    do not forgot to restart apache service

    虚拟主机示例:

    <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

相关问题