0

Hi I'm working on a website using apache 2.2 and feathersjs. on this website we have DV SSL so we can't access subdomains using https.

my node application is running on 3030 port. so I can access to feathersjs app using this address:

http://mywebsite.com:3030

but https://mywebsite.com:3030 not working.

I need to use a Location like https://mywebsite.com/socket/ to connect to feathersjs websocket (guess ws://localhost:3030)

here is client side code:

const host = 'https://mywebsite.com/socket';
const socket = io(host,{
            transports: ['websocket'],
            forceNew: true
        });

I need httpd configuration to connect ws over https.

post_virtualhost_global.conf

<VirtualHost 185.173.106.42:80>
  ServerName mywebsite.com

    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule .* ws://localhost:3030%{REQUEST_URI} [P]

    ProxyPass /socket http://localhost:3030/
    ProxyPassReverse /socket http://localhost:3030/

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

</VirtualHost>

<VirtualHost 185.173.106.42:443>
  ServerName freevery.com

    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule .* ws://localhost:3030%{REQUEST_URI} [P]

    ProxyPass /socket http://localhost:3030/
    ProxyPassReverse /socket http://localhost:3030/

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    <Location /feathers>
        ProxyPass http://localhost:3030/
        ProxyPassReverse http://localhost:3030/
    </Location>

</VirtualHost>

if I try to connect web socket using http://mywebsite.com/socket it says

Failed to load http://mywebsite.com/socket.io/?EIO=3&transport=polling&t=L-1lgZ1: Redirect from 'http://mywebsite.com/socket.io/?EIO=3&transport=polling&t=L-1lgZ1' to 'https://mywebsie.com/socket.io/?EIO=3&transport=polling&t=L-1lgZ1' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access.

and if I try to connect web socket using https://mywebsite.com/socket it says

Failed to load https://mywebsite.com/socket.io/?EIO=3&transport=polling&t=L-1lUP5: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access. The response had HTTP status code 404.

I added Header set Access-Control-Allow-Origin "*" to my .htaccess file but problem exists.

what is wrong with my configurations?

2
  • Try adding ProxyPreserveHost On Commented Nov 3, 2017 at 13:13
  • now I have websocket.js:112 WebSocket connection to 'ws://mywebsite.com/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 301 Commented Nov 3, 2017 at 14:19

1 Answer 1

0

Problem solved. Apache had conflicts with nginx and 301 error was form it. So I used nginx to proxy websocket and it's working on a subdomain without any problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.