Proxy websocket wss:// to ws:// apache -


i searched alot couldnt connect websocket wss:// , found there way proxy wss://domain.com:9090 , apache apply proxy on , redirect request normal ws://domain.com:9090 server running

proxypass /websocket ws://domain.com:9090 proxypassreverse /websocket ws://domain.com:9090 

this code in apache config send request address ended /websocket ws://domain.com:9090 ex : ws://websocket ws://domain.com:9090

i want wss:// ex wss://websocket must point ws://domain.com:9090

it dosnt work , error in browser console :

failed: error in connection establishment: net::err_connection_refused 

is there mistake here ? .

i worked 24 hours find , searched lot of forum no 1 write success. here server configuration :

centos release 6.7 , apache 4.2.18

here did : first found modules/mod_proxy_wstunnel.so must enable in apache config file , apache didn't have module , after lot of search found module available in apache 2.4.5 , later.

https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html

i downloaded https://archive.apache.org/dist/httpd/httpd-2.4.18.tar.gz extracted httpd-2.4.18\modules\proxy\mod_proxy_wstunnel.c , uploaded server root terminal compile again these commonds :

chmod 755 mod_proxy_wstunnel.c #set permission pxs -i -a -c mod_proxy_tunnel.c #compile module 

pxs command did compile module , wrote in apache config file load it

loadmodule proxy_wstunnel_module modules/mod_proxy_wstunnel.so 

after added these lines end of apache config file :

rewriteengine on proxyrequests off proxypreservehost on proxypass /myws ws://mysite.com:8091 proxypassreverse /myws ws://mysite.com:8091 

and : works ! in client side js can set ws url :

var protocol = 'ws://';  if (window.location.protocol === 'https:') {             protocol = 'wss://';    }   var wsuri =protocol+ "mysite.com/myws";     var ws = new websocket(wsuri); 

and forward request ws://mysite.com:8091 doesnt matter page loaded https or http , direct request ended /myws ws://mysite.com:8091


Comments