Answer the question
In order to leave comments, you need to log in
Why 502 bat gateway(nginx, websocket)?
Good afternoon.
I'm trying to set up nginx for webscoket.
Launched such a server
<?php
$ws = new swoole_websocket_server('127.0.0.1', 9502);
$ws->on('open', function ($ws, $request) {
// print_r($request);
$ws->push($request->fd, "hello, welcome!\n");
});
$ws->on('message', function ($ws, $frame) {
echo "We recieve message: {$frame->data}\n";
$ws->push($frame->fd, "Got it!\n");
});
$ws->on('close', function ($ws, $fd) {
echo "client-{$fd} is closed\n";
});
$ws->start();
server {
listen 80;
listen [::]:80;
server_name ws-chat.test;
root /var/www/ws-chat;
index index.php index.html index.htm;
location /ws/ {
proxy_pass http://127.0.0.1:9502;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
error_log /var/log/nginx/app_error.log;
access_log /var/log/nginx/app_access.log;
}
var socket = new WebSocket("ws:ws-chat.test/ws/");
proxy_pass http://workspace:9502;
Answer the question
In order to leave comments, you need to log in
UPD: Decided. In the nginx config it was necessary to registerproxy_pass http://workspace:9502;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question