Answer the question
In order to leave comments, you need to log in
How to deploy websocket to wss?
Hello.
Chat deployment on websockets has turned into some kind of wild hemorrhoid. You are our last hope, friends.
Django (Python) project. For the source, I took this repository https://github.com/Bearle/django-private-chat
I start the
websocket server:
class Command(BaseCommand):
help = 'Starts message center chat engine'
def handle(self, *args, **options):
asyncio.async(
websockets.serve(
handlers.main_handler,
'0.0.0.0',
'5002'
)
)
logger.info('Chat server started')
asyncio.async(handlers.new_messages_handler(channels.new_messages))
asyncio.async(handlers.users_changed_handler(channels.users_changed))
asyncio.async(handlers.gone_online(channels.online))
asyncio.async(handlers.check_online(channels.check_online))
asyncio.async(handlers.gone_offline(channels.offline))
asyncio.async(handlers.is_typing_handler(channels.is_typing))
asyncio.async(handlers.read_message_handler(channels.read_unread))
loop = asyncio.get_event_loop()
loop.run_forever()
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 5002;
location / {
proxy_pass http://ip хоста:5002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
server {
server_name домен;
listen 80;
listen 443 default_server ssl;
ssl_certificate /home/dev/c.pem;
ssl_certificate_key /home/dev/k.key;
location /static/ {
root /home/dev/gamemode_prj/gamemode/;
}
location /media/ {
root /home/dev/gamemode_prj/gamemode/;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/dev/gamemode_prj/gamemode/gamemode/gamemode.sock;
}
websocket = new WebSocket(wss://domen + '{{ request.session.session_key }}/' + opponent_username);
WebSocket connection to 'wss://domen/yl8xetcvg6sbbqg2cdu15qkjhshvf0cr/Vasya' failed: Error during WebSocket handshake: Unexpected response code: 404
162.158.91.162 - - [29/May/2018:05:50:53 -0400] "GET /yl8xetcvg6sbbqg2cdu15qkjhshvf0cr/Vasya HTTP/1.1" 404 1508 "-" "Mozilla/5.0 (Windows NT 10.0; W$
162.158.91.162 - - [29/May/2018:05:50:57 -0400] "GET /static/js/scrollMonitor.js.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) $
Answer the question
In order to leave comments, you need to log in
You have done proxying to a websocket in the wrong server section, add it to the section where port 443 and ssl are registered
Well, you didn't make a wss(https) server for the socket...
Either connect the certificate to the server itself or to nginx before proxying to the socket.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question