Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPS and Websockets #296

Closed
sova opened this issue Mar 3, 2017 · 6 comments
Closed

HTTPS and Websockets #296

sova opened this issue Mar 3, 2017 · 6 comments

Comments

@sova
Copy link

sova commented Mar 3, 2017

Hello,

Is there something special I should know if I want to use Sente with HTTPS?

I am trying now to run my clojurescript project that has a clojure backend on my SSL-enabled Apache box and my websockets are telling me that "200" is an unexpected error code o_O

@sova
Copy link
Author

sova commented Mar 3, 2017

sente-https-ssl-socket-funk

@danielcompton
Copy link
Collaborator

Sente is expecting a 1xx (I forget the exact number) status code to switch protocols from HTTP(S) to WS(S). Can you check that you've configured Apache to accept WS connections?

@sova
Copy link
Author

sova commented Mar 3, 2017

Oh cool, I did not know that. I suspected as much, that Apache2 would be the culprit! Thanks a lot for the quick feedback, I shall look into it! I'm not sure where that switch lives.

@sova
Copy link
Author

sova commented Mar 4, 2017

Well, after some battling with Apache2.4.7 I now have some educated questions:

My "/login" is also not working, throwing me a 403 Forbidden. Not sure why that is happening.

Is there a particular WebSocket port that sente uses, or is redirecting to the port of my running application through lein start (i.e. wss://localhost:56721/ ) sufficient?

Where can I learn more about how sente does websockets and WSS if it's https? Should I just have it redirect to ws:// ~ and expect that it shall shift itself?

Thanks for any help.

@sova
Copy link
Author

sova commented Mar 5, 2017

Hello

I eventually had to do a lot of fun stuff in my apache configuration (/sites-enabled/mydomain-ssl.conf)

One instruction that was absolutely necessary to get websockets to work looks like this

<VirtualHost *:80>
  ServerName www.domain2.com

  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /(.*)           ws://localhost:3001/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)           http://localhost:3001/$1 [P,L]

  ProxyPassReverse / http://localhost:3001/
</VirtualHost>

Which I got from this awesome stack overflow answer (the second one) here https://stackoverflow.com/questions/27526281/websockets-and-apache-proxy-how-to-configure-mod-proxy-wstunnel/35141086#35141086

In case somebody else is going nuts with SSL-based websockets over apache2.4.7 or similar

@sova sova closed this as completed Mar 5, 2017
@WorldsEndless
Copy link

Thank you for this fix! It rescued our application after a lot of debugging. I wrote about solving our issue here: https://tech.toryanderson.com/2020/10/26/websockets-for-clojure-sente-in-apache-reverse-proxy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants