【问题标题】:Able to redirect https to http but not able to redirect wss to ws能够将 https 重定向到 http 但不能将 wss 重定向到 ws
【发布时间】:2020-04-25 19:47:21
【问题描述】:

我正在使用网络套接字。在 apache 中,我可以通过在配置文件中进行以下设置来从 https 重定向到 http:

      <VirtualHost *:443>
      # Common SSL Config
      ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
      SSLEngine on
      # wss redirects to working ws protocol

            SSLCertificateFile      /etc/ssl/certs/apache-selfsigned.crt
            SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
            ProxyPass "/"  "http://ec2-13-52-248-221.us-west-1.compute.amazonaws.com" retry=0 keepalive=On

      </VirtualHost>

但相同的配置(如上)我更改如下

     <VirtualHost *:443>
      # Common SSL Config
      ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
      SSLEngine on
      # wss redirects to working ws protocol

            SSLCertificateFile      /etc/ssl/certs/apache-selfsigned.crt
            SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
            ProxyPass "/wss"  "ws://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080" retry=0 keepalive=On

      </VirtualHost>

我无法从 wss 重定向到 ws

如果是 Wss,我在发送请求时使用以下网址:

    wss://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080/wss

【问题讨论】:

    标签: apache websocket webrtc ratchet ws


    【解决方案1】:

    经过 24 小时的努力,我终于找到了解决方案:这个配置对我有用

    首先通过在 windows 中的 httpd.conf 文件中启用这些模块来加载以下模块

    proxy_wstunnel_module modules/mod_proxy_wstunnel.so
    

    在 linux 中,您可以通过以下命令启用此模块

    sudo a2enmod proxy proxy_balancer proxy_wstunnel proxy_http
    

    然后只需将以下行添加到 apache.conf 文件或 httpd-vhosts.conf 文件中

    RewriteEngine on
    ProxyRequests Off
    ProxyPreserveHost on
    ProxyPass /ws ws://192.168.43.31:8080 retry=0 keepalive=On 
    ProxyPassReverse /ws  ws://192.168.43.31:8080 retry=0
    

    在 Javascript 文件中的变化是这样的:

    if(location.protocol === 'http:'){
      var conn = new WebSocket('ws://192.168.43.31/ws');
     }
    else{
      var conn = new WebSocket('wss://192.168.43.31/ws');
    }
    

    所以这个 apache 会将所有有 ws 的请求重定向回 8080 端口

    【讨论】:

      猜你喜欢
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      • 2017-11-24
      • 2017-03-24
      • 2013-09-03
      • 1970-01-01
      • 2019-12-17
      相关资源
      最近更新 更多