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

Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR #68

Open
ledzgio opened this issue Oct 7, 2020 · 1 comment
Open

Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR #68

ledzgio opened this issue Oct 7, 2020 · 1 comment

Comments

@ledzgio
Copy link

ledzgio commented Oct 7, 2020

  • django-private-chat version: 0.3.0
  • Django version: 2.2.12
  • Python version: 3.7.3
  • Operating System: Debian buster

Description

I am having issues in production where I am running nginx on HTTPS and uwsgi deployed on an EC2 instance.

In the browser console I get this error:
WebSocket connection to 'wss://ec2-***:5002/session_id/username' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR

What I Did

Here are my settings:
CHAT_WS_SERVER_HOST = 'ec2-***' # here I am using EC2 Public IPv4 DNS
CHAT_WS_SERVER_PORT = 5002
CHAT_WS_SERVER_PROTOCOL = 'wss'

I run the server as following:
python manage.py run_chat_server

And in the server console I get:


`07.10.20 16:58:49:DEBUG:Invalid handshake
Traceback (most recent call last):
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/http.py", line 96, in read_request
request_line = await read_line(stream)
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/http.py", line 219, in read_line
raise EOFError("line without CRLF")
EOFError: line without CRLF
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/server.py", line 233, in read_http_request
path, headers = await read_request(self.reader)
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/http.py", line 98, in read_request
raise EOFError("connection closed while reading HTTP request line") from exc
EOFError: connection closed while reading HTTP request line

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/server.py", line 134, in handler
extra_headers=self.extra_headers,
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/server.py", line 526, in handshake
path, request_headers = await self.read_http_request()
File "/home/admin/poc_platform/env/lib/python3.7/site-packages/websockets/server.py", line 235, in read_http_request
raise InvalidMessage("did not receive a valid HTTP request") from exc
websockets.exceptions.InvalidMessage: did not receive a valid HTTP request
07.10.20 16:58:49:DEBUG:server > HTTP/1.1 400 Bad Request

Any idea?
thanks

@ledzgio
Copy link
Author

ledzgio commented Oct 8, 2020

If anyone is interested, I've managed to get it working on AWS.

Basically what I did is:

Edit the connection string in views.py as follows:

wss://domain.com/ws/session_id/username

Edit handlers.py, function main_handler to get username and session_id based on the new connection string defined above

Add this setting under nginx SSL server:

location /ws {
        proxy_pass http://chatserver;
        proxy_connect_timeout 7d;
        proxy_read_timeout 7d;
        proxy_send_timeout 7d;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
}

add the following outside the server directives:

upstream chatserver {
      	server 127.0.0.1:5002  max_fails=1 fail_timeout=20s;
}

and here are the settings.py:

CHAT_WS_SERVER_HOST = '127.0.0.1'
CHAT_WS_SERVER_PORT = 5002
CHAT_WS_SERVER_PROTOCOL = 'wss'

Now start the wesocket server as following:

python manage.py run_chat_server

Hope this help those that had issues like me. Cheers.

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

1 participant