I’m trying to setup Apache 2.4 (On Virtualmin) to forward wss://sub.domain.com
requests to ws://localhost:6001
and I’m not having luck. I’ve followed countless tutorials, and looked through plenty of Stackoverflow questions – and I’m still stumped.
I have proxy
, proxy_http
, proxy_wstunnel
, and rewrite
installed and enabled.
First I tried:
ServerName sub.domain.com
RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:6001/$1 [P,L]
ProxyPass / http://127.0.0.1:6001/
ProxyPassReverse / http://127.0.0.1:6001/
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
SSLCertificateChainFile /path/to/chain.pem
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Then I tried:
ServerName sub.domain.com
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:6001/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:6001/$1 [P,L]
ProxyPreserveHost on
ProxyPass / ws://localhost:6001/
ProxyPassReverse / ws://localhost:6001/
...ssl directives
And just about every combination of the two.
As for the websocket server, I’m using Laravel-websockets on port 6001.
What am I doing wrong?
2
Answers
Someone had replied with an answer but apparently deleted it, the below works in Chrome and Insomnia (But not Firefox - but that could be a Laravel-websockets problem). Reposting it in case it helps anyone else:
You can either add the above to your virtual server config, or htaccess.
I setup a full test in the cloud to verify this. This works – as simple as it is.
I tested with a super-simple ws server from https://github.com/Theldus/wsServer
configured the DNS to
ws.mydomain.com
and then ran https://www.piesocket.com/websocket-tester on wss://ws.mydomain.com . Works.