Локально работал с сокетами и соединение устанавливалось
var socket = new WebSocket("ws://domain:8060/ws");
socket.onopen = function() {
console.log("Соединение установлено.");
};
Когда добавил сокет соединение на сайт, который работает через ssl получаю ошибку
index.html:18 WebSocket connection to 'wss://domain/ws' failed: Error during WebSocket handshake: Unexpected response code: 301
Настройки nginx
server {
if ($host !~ ^(domain)$ ) {
return 444;
}
listen 443;
ssl on;
ssl_certificate /etc/ssl/domain.crt;
ssl_certificate_key /etc/ssl/domainkey;
server_name domain;
# Django
location /static_admin/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
alias /home/backend/static;
}
location /strawberry/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
}
location /api/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
}
location /r/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
}
#############
# Ws server #
#############
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 5000s;
proxy_pass http://127.0.0.1:8060;
}
# Node
location / {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8000;
}
location ~* /static/.*\.(gif|jpg|jpeg|bmp|png)$ {
include sites-enabled/proxy.conf;
#proxy_pass http://127.0.0.1:8000;
root /home/front/public/;
}
}
server {
listen 80;
server_name domain;
# Django
location /static_admin/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
alias /home/backend/static;
}
location /strawberry/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
}
location /api/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
}
location /r/ {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8080;
}
#############
# Ws server #
#############
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 5000s;
proxy_pass http://127.0.0.1:8060;
}
# Node
location / {
include sites-enabled/proxy.conf;
proxy_pass http://127.0.0.1:8000;
}
location ~* /static/.*\.(gif|jpg|jpeg|bmp|png)$ {
include sites-enabled/proxy.conf;
#proxy_pass http://127.0.0.1:8000;
root /home/front/public/;
}
}
Сокет сервер
import asyncio
import logging
from aiohttp import web
from routes import setup_routes
# Logging
# logging.basicConfig(filename="sample.log", level=logging.INFO)
loop = asyncio.get_event_loop()
app = web.Application(loop=loop)
app['websockets'] = []
setup_routes(app)
web.run_app(app, host='0.0.0.0', port=8060)