[英]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.