A
A
Alexey Bondarev2019-03-17 18:42:39
go
Alexey Bondarev, 2019-03-17 18:42:39

Websocket stopped working after switching to HTTPS. What to change?

There is a service written in Go. An Http server on port 8090 has been raised on it, and a socket has also been raised there.
There is a Php application that listens for events on this socket. All this goodness is on the same server, the application accesses the service through JS like this:

conn = new WebSocket("ws://192.168.1.20:8090/events");

Everything works, everything is great. It's time to bind PUSH notifications that require HTTPS to the application. We raise Https, we get pushes, but we see that the socket has fallen off. Error in console:
Mixed Content: The page at ' https://mysite.ru/admin/service ' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://192.168.1.20:8090/events' . This request has been blocked; this endpoint must be available over WSS.
Googling, we see that now you need to connect with the WSS prefix. We change the prefix, we get the following:
WebSocket connection to 'wss://192.168.1.20:8090/events' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR
What we tried:
I read that you can get around the problem through nginx proxy, but how? Catch a connection on port 8090 and send it to http so that everything is the same as before? Tried it, didn't bring much success.
Add https support to GO service? But what certificate? The same as for the application itself?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Bondarev, 2019-03-20
@lexbond13

Thanks for the advice, the solution was as follows:
1. In GO we connect the same SSL certificates that are used for Https for the application
2. We check that the service is available on the https://mysite.ru:8090
domain 3. We change the connection address to the sockets in the application from ws://192.168.1.20:8090/events to wss://mysite.ru:8090/events , since we have a certificate for the mysite domain.
4. We check - everything works!
The nuance is that now the data transfer occurs with very large delays. This is probably due to the connection being established via Https.

R
Robur, 2019-03-17
@Robur

Did you enable SSL support for websockets on the server, or did you just change the prefix in the line?
On your question, it is not clear who is listening to the socket - go or php. I understand that all the same go, configure wss in the same way as https, if https works without problems for you, then there should be no problems with wss

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question