I have one site configured to work with ssl. Every request that I receive I redirect to 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://
I created a new file locale only to connect o my websocket that is in production. When I connetc using ws://domain
it work, when i change to wss://domain
I got the error message.
I’m using ubuntu 18:04, Apache/2.4.18 and Rails action cable.
My Vhost is
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ServerAdmin [email protected]
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 [email protected]
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/");
I get Firefox can’t establish a connection to the server at wss://
, but if I call exampleSocket = new WebSocket("ws://domain.com/cable/");
the connection work.
On site if I call exampleSocket = new WebSocket("ws://domain.com/cable/");
, it dont work because of the ssl, and I get SecurityError: The operation is insecure.
Anyone can help with this?
2
Answers
I fixed the problem. Everything was going wrong because of the order of the proxypass on apache configuration file. I changed the file to this
It occur beacause of the ProxyPass / match in all requests that are incoming and the request
/cable/
was never reached.It is unlikely that your unknown Websocket server can do both
ws://
andwss://
on the same port 28080. It is more likely that it can do onlyws://
, i.e. you should forward tows://
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 internalhttp://
and not not one tohttp://
and the other tohttps://
.