Parag Jain
Parag Jain

Reputation: 662

Able to redirect https to http but not able to redirect wss to ws

I am working with web sockets. In apache I am able to redirect from https to http by doing below setting in configuration file:

      <VirtualHost *:443>
      # Common SSL Config
      ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
      SSLEngine on
      # wss redirects to working ws protocol

            SSLCertificateFile      /etc/ssl/certs/apache-selfsigned.crt
            SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
            ProxyPass "/"  "http://ec2-13-52-248-221.us-west-1.compute.amazonaws.com" retry=0 keepalive=On

      </VirtualHost>

But same configuration(As Above) I change as follow

     <VirtualHost *:443>
      # Common SSL Config
      ServerName ec2-13-52-248-221.us-west-1.compute.amazonaws.com
      SSLEngine on
      # wss redirects to working ws protocol

            SSLCertificateFile      /etc/ssl/certs/apache-selfsigned.crt
            SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
            ProxyPass "/wss"  "ws://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080" retry=0 keepalive=On

      </VirtualHost>

I am not able to redirect from wss to ws

In Case of Wss I am using below url while sending request :

    wss://ec2-13-52-248-221.us-west-1.compute.amazonaws.com:8080/wss

Upvotes: 0

Views: 1488

Answers (1)

Parag Jain
Parag Jain

Reputation: 662

After 24 Hours of efforts Finally I got the solution: This configuration worked for me

First Load following modules by enabling this modules in httpd.conf file in windows

proxy_wstunnel_module modules/mod_proxy_wstunnel.so

In linux you can enable this modules by following commands

sudo a2enmod proxy proxy_balancer proxy_wstunnel proxy_http

Then Just add following lines to apache.conf file or httpd-vhosts.conf file

RewriteEngine on
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /ws ws://192.168.43.31:8080 retry=0 keepalive=On 
ProxyPassReverse /ws  ws://192.168.43.31:8080 retry=0

In Javascript file changes are like this:

if(location.protocol === 'http:'){
  var conn = new WebSocket('ws://192.168.43.31/ws');
 }
else{
  var conn = new WebSocket('wss://192.168.43.31/ws');
}

so from this apache will redirect all request which has ws in back to 8080 port

Upvotes: 1

Related Questions