Есть сервер centos-release-7-6.1810.2.el7.centos.x86_64.
Софт Centrifugo v3.1.0 (Go version: go1.17.3)
Так вот центрифугу установил, вроде запустилась без ошибок.
Если напрямую заходить в центрифугу ип_адрес:9000 то заходит.
А вот если, я хочу привязать ее к сайту, через https://my_site/connection/websocket то не фига не работает, в браузере выходит сообщение Bad Request , не пойму почему.
log nginx
Код: Выделить всё
12.4.12.78 - - [11/Nov/2021:14:11:26 +0100] "GET /connection/websocket HTTP/1.1" 400 12 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0"
Код: Выделить всё
cat /etc/centrifugo/config.json
{
"token_hmac_secret_key": "my",
"admin_password": "my",
"admin_secret": "my",
"api_key": "my",
"port": 9000,
"admin": true
}
Код: Выделить всё
cat /lib/systemd/system/centrifugo.service
[Unit]
Description=Centrifugo services
After=network.target syslog.target
[Service]
User=centrifugo
Group=centrifugo
LimitNOFILE=55555
Environment="CONFIG=/etc/centrifugo/config.json"
ExecStartPre=/usr/bin/centrifugo checkconfig -c $CONFIG
ExecStart=/usr/bin/centrifugo -c $CONFIG
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -SIGTERM $MAINPID
TimeoutStopSec=10
KillMode=control-group
RestartSec=1
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=centrifugo
[Install]
WantedBy=multi-user.target
Alias=centrifugo.service
Код: Выделить всё
# systemctl status centrifugo
● centrifugo.service - Centrifugo services
Loaded: loaded (/usr/lib/systemd/system/centrifugo.service; enabled; vendor preset: disabled)
Active: active (running) since Чт 2021-11-11 13:51:58 CET; 7min ago
Process: 28567 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 30498 ExecStartPre=/usr/bin/centrifugo checkconfig -c $CONFIG (code=exited, status=0/SUCCESS)
Main PID: 30511 (centrifugo)
CGroup: /system.slice/centrifugo.service
└─30511 /usr/bin/centrifugo -c /etc/centrifugo/config.json
ноя 11 13:51:58 n50 systemd[1]: Starting Centrifugo services...
ноя 11 13:51:58 n350 systemd[1]: Started Centrifugo services.
ноя 11 13:51:58 n350 centrifugo[30511]: {"level":"info","version":"3.1.0","runtime":"go1.17.3","pid":30511,"engine":"Memory","gomaxprocs":8,"time":...trifugo"}
ноя 11 13:51:58 n350 centrifugo[30511]: {"level":"info","path":"/etc/centrifugo/config.json","time":"2021-11-11T13:51:58+01:00","message":"using config file"}
ноя 11 13:51:58 n350 centrifugo[30511]: {"level":"info","algorithms":"HS256, HS384, HS512","time":"2021-11-11T13:51:58+01:00","message":"enabled JW...rifiers"}
ноя 11 13:51:58 n350 centrifugo[30511]: {"level":"info","time":"2021-11-11T13:51:58+01:00","message":"serving websocket, API, admin endpoints on :9000"}
Hint: Some lines were ellipsized, use -l to show in full.
Код: Выделить всё
cat /etc/nginx/vhosts/my_site/my_site.io.conf
upstream centrifugo {
ip_hash;
server 127.0.0.1:9000;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 1.1.1.1:8000;
}
server {
listen 1.1.1.1:80;
root /usr/local/www/default;
}
server {
listen 1.1.1.1:80;
server_name my_site.io my_site.online;
charset off;
index index.php index.html;
disable_symlinks if_not_owner from=$root_path;
ssi on;
set $root_path /var/www/my_site.io/;
root $root_path;
location / {
try_files $uri $uri/ =404;
}
location /p {
rewrite /p/(.*) /$1 break;
proxy_pass http://my_site.io/ref.php?id=$1;
proxy_redirect off;
proxy_set_header Host $host;
}
location /centrifugo/ {
rewrite ^/centrifugo/(.*) /$1 break;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://centrifugo;
}
location /connection/websocket {
rewrite ^/centrifugo(.*) $1 break;
proxy_pass http://centrifugo;
proxy_buffering off;
keepalive_timeout 65;
proxy_read_timeout 60s;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
expires 5d;
}
location /websocket {
proxy_pass http://1.1.1.1:8000/;
proxy_redirect http://1.1.1.1:8000/ /websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log /var/www/httpd-logs/my_site-ssl-websocket.access.log;
}
location ^~ /\?hash {
proxy_pass http://1.1.1.1:8000/;
proxy_redirect http://1.1.1.1:8000/ /;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.php$ {
fastcgi_pass unix:/var/www/php-fpm/my_site.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@my_site.io";
fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
try_files $uri =404;
}
}