Подскажите, пожалуйста, в чем проблема?
Если я стучусь по IP то тест сокетов проходит без ошибок. Пример:
http://123.45.678.91:4000
Если через nginx - ошибка. Пример:
https://sitename.ru/server
const app = express();
const http_server = http.createServer(app);
export const io = socket_io(
new Server(
http_server,
{
cors: {
origin: '*'
}
}
)
);
конфиг:
server {
# root /usr/share/nginx/html/dist/frontend;
# index index.html index.htm;
server_name sitename.ru www.sitename.ru;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/sitename.ru/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/sitename.ru/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
add_header Access-Control-Allow-Origin localhost;
location / {
rewrite /(.*) /$1 break;
proxy_pass http://127.0.0.1:4200;
proxy_pass_header Server;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 5000m;
}
location /server {
# rewrite /(.*) /$1 break;
proxy_pass http://127.0.0.1:4000;
proxy_pass_header Server;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 5000m;
}
location /socket.io/ {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_send_timeout 86400;
proxy_read_timeout 86400;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
# New
proxy_connect_timeout 15s;
proxy_buffers 512 256M;
proxy_buffer_size 256M;
}
location @proxy {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_pass https://sitename.ru;
proxy_redirect off;
}
}
server {
if ($host = www.sitename.ru) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = sitename.ru) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name sitename.ru www.sitename.ru;
return 404; # managed by Certbot
}