Reputation: 2745
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:
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?
Upvotes: 0
Views: 1029
Reputation: 2745
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.
Upvotes: 0