简体   繁体   English

Websocket仅适用于ws://,但不适用于wss://

[英]Websocket only work with ws:// but not with wss://

I have one site configured to work with ssl. 我有一个配置为使用ssl的站点。 Every request that I receive I redirect to https. 我收到的每个请求都会重定向到https。 Recently I implemented a websocket on it, and it work fine on development, so when I put in production I started to get this error Firefox can't establish a connection to the server at wss:// 最近我在它上面实现了一个websocket,它在开发上工作得很好,所以当我投入生产时我开始得到这个错误Firefox can't establish a connection to the server at wss://

I created a new file locale only to connect o my websocket that is in production. 我创建了一个新的文件区域设置,仅用于连接正在生产的我的Websocket。 When I connetc using ws://domain it work, when i change to wss://domain I got the error message. 当我使用ws://domain connetc它工作,当我更改为wss://domain我收到了错误消息。

I'm using ubuntu 18:04, Apache/2.4.18 and Rails action cable. 我正在使用ubuntu 18:04,Apache / 2.4.18和Rails动作电缆。

My Vhost is 我的虚拟主机是

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    ServerAdmin contato@domain.com
    DocumentRoot /var/www/domain.com/public
    ProxyRequests off
    ProxyPreserveHost On
    LogLevel error

    <Location />
        Order allow,deny
        Allow from all
        Require all granted
    </Location>

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    ProxyPass /cable/  ws://127.0.0.1:28080/cable/
    ProxyPassReverse /cable/ ws://127.0.0.1:28080/cable/

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

<VirtualHost *:443>
    ServerName domain.com
    ServerAlias www.domain.com
    ServerAdmin contato@domain.com
    DocumentRoot /var/www/domain.com/public
    ProxyRequests off
    ProxyPreserveHost On
    LogLevel error

    <Location />
        Order allow,deny
        Allow from all
        Require all granted
    </Location>

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    ProxyPass /cable/  wss://127.0.0.1:28080/cable/
    ProxyPassReverse /cable/ wss://127.0.0.1:28080/cable/

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

On localhost out of the domain If I call exampleSocket = new WebSocket("wss://domain.com/cable/"); 在localhost之外的域名如果我调用exampleSocket = new WebSocket("wss://domain.com/cable/"); I get Firefox can't establish a connection to the server at wss:// , but if I call exampleSocket = new WebSocket("ws://domain.com/cable/"); 我得到Firefox can't establish a connection to the server at wss:// ,但如果我调用exampleSocket = new WebSocket("ws://domain.com/cable/"); the connection work. 连接工作。

On site if I call exampleSocket = new WebSocket("ws://domain.com/cable/"); 在现场,如果我调用exampleSocket = new WebSocket("ws://domain.com/cable/"); , it dont work because of the ssl, and I get SecurityError: The operation is insecure. ,由于ssl而无法使用,并且我收到SecurityError: The operation is insecure.

Anyone can help with this? 任何人都可以帮忙吗?

<VirtualHost *:80>
    ...
    ProxyPass / http://127.0.0.1:8080/
    ...
    ProxyPass /cable/  ws://127.0.0.1:28080/cable/
    ...
<VirtualHost *:443>
    ...
    ProxyPass / http://127.0.0.1:8080/
    ...
    ProxyPass /cable/  wss://127.0.0.1:28080/cable/

It is unlikely that your unknown Websocket server can do both ws:// and wss:// on the same port 28080. It is more likely that it can do only ws:// , ie you should forward to ws:// for both port 80 and 443. Note that this is similar to what you are already correctly doing for the normal traffic: both port 80 and port 443 is forwarded to the internal http:// and not not one to http:// and the other to https:// . 您未知的Websocket服务器不太可能在同一端口28080上同时执行ws://wss:// 。它更可能只能执行ws:// ,即您应该转发到ws://以获取请注意,这与您正在为正常流量正确执行的操作类似:端口80和端口443都转发到内部http://而不是一个转发到http://和另一个到https://

I fixed the problem. 我解决了这个问题。 Everything was going wrong because of the order of the proxypass on apache configuration file. 由于apache配置文件上的proxypass的顺序,一切都出错了。 I changed the file to this 我把文件改成了这个

<VirtualHost *:80>
    ServerName suaradioonline.com
    ServerAlias www.suaradioonline.com
    ServerAdmin contato@suaradioonline.com.br
    DocumentRoot /var/www/suaradioonline.com/public
    ProxyRequests off
    ProxyPreserveHost On
    LogLevel error

    <Location />
        Order allow,deny
        Allow from all
        Require all granted
    </Location>

    ProxyPass /cable/  ws://127.0.0.1:28080/cable/
    ProxyPassReverse /cable/ ws://127.0.0.1:28080/cable/

    ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/

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

<VirtualHost *:443>
        ServerName suaradioonline.com
        ServerAlias www.suaradioonline.com
        ServerAdmin contato@suaradioonline.com.br
        DocumentRoot /var/www/suaradioonline.com/public
        ProxyRequests off
        ProxyPreserveHost On
        LogLevel error

        <Location />
            Order allow,deny
            Allow from all
            Require all granted
        </Location>

        ProxyPass /cable/  ws://127.0.0.1:28080/cable/
        ProxyPassReverse /cable/ ws://127.0.0.1:28080/cable/

        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/

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

It occur beacause of the ProxyPass / match in all requests that are incoming and the request /cable/ was never reached. 这是因为所有传入的请求中都存在ProxyPass /匹配,并且从未达到请求/cable/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用em-websocket gem无法将连接更改为&#39;ws://&#39;RUBY - Using em-websocket gem can't change connection to 'ws://' RUBY 与&#39;ws://example.com/cable&#39;的WebSocket连接失败:意外的响应代码:404 - WebSocket connection to 'ws://example.com/cable' failed: Unexpected response code: 404 Faye,Websocket连接问题:无法与ws:// localhost:9292 / faye建立连接 - Faye, websocket connection problems: can't establish connection with ws://localhost:9292/faye 与&#39;ws:// localhost:35729 / livereload&#39;的WebSocket连接失败:连接建立错误:net :: ERR_CONNECTION_REFUSED - WebSocket connection to 'ws://localhost:35729/livereload' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED 使 WebSocket 与 Ruby on Rails、Puma 和 Nginx 一起工作 - Make WebSocket work with Ruby on Rails vs Puma and Nginx 使用Nginx和Unicorn,Websocket-rails不适用于生产环境 - Websocket-rails doesn't work on production evironment with Nginx and Unicorn 使用websocket_rails gem的Rails应用中的方法broadcast_message不起作用 - Method broadcast_message in a rails app with websocket_rails gem don't work Javascript仅在刷新页面后才能工作 - Javascript will only work after refreshing the page 这是仅OpenTokRTC javascript框架吗? 还是可以在Rails上使用? - Is this OpenTokRTC javascript framework only? Or will it work on Rails too? Redis实例只能用于1个项目吗? - Is a redis instance can only work for 1 project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM