map $http_upgrade $connection_upgrade{
default upgrade;
'' close;
}
upstream workman_jx{
server 127.0.0.1:50000;
}
server{
listen 80;
server_name ws.iwwee.com;
location / {
proxy_pass http://workman_jx;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
# error.log
2020/06/17 11:00:25 [error] 26657#0: *2122075 upstream timed out (110: Connection timed out) while reading upstream, client: 120.239.110.113, server: ws.iwwee.com, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:50000/", host: "ws.iwwee.com"
但是直接訪問不經(jīng)過nginx,直接訪問ws.iwwee.com:50000
又可以使用。
workman的log也沒報錯
workman的status如下:
Workerman[jx_50000] status
----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:4.0.5 PHP version:7.1.31
start time:2020-05-28 11:54:26 run 19 days 15 hours
load average: 0.1, 0, 0 event-loop:\Workerman\Events\Select
1 workers 4 processes
worker_name exit_status exit_count
none 0 4
----------------------------------------------PROCESS STATUS---------------------------------------------------
pid memory listening worker_name connections send_fail timers total_request qps status
16549 2M websocket://0.0.0.0:50000 none 0 0 0 0 0 [idle]
16551 2M websocket://0.0.0.0:50000 none 0 0 0 0 0 [idle]
16553 2M websocket://0.0.0.0:50000 none 0 0 0 1 0 [idle]
16555 2M websocket://0.0.0.0:50000 none 0 0 0 3 0 [idle]
----------------------------------------------PROCESS STATUS---------------------------------------------------
Summary 8M - - 0 0 0 4 0 [Summary]
nginx version: nginx/1.12.2
workman代碼如下:
<?php
use Workerman\Worker;
require_once __DIR__ . '/core/vendor/autoload.php';
$db_config = require_once __DIR__ . '/config/jx_db.php';
$ws_worker = new Worker("websocket://0.0.0.0:50000");
// 啟動4個進程對外提供服務(wù)
$ws_worker->count = 4;
nginx version: nginx/1.12.2
經(jīng)過測試,workman能收到請求,但是無法返回到nginx。
環(huán)境:套路云
端口:50000
出入規(guī)則已經(jīng)開放
server {
listen 80;
server_name example.com;
location /
{
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
}
}
我用的類似這樣的配置,沒有問題
剛剛換成您這個配置了,但是還是不行。在服務(wù)器使用curl已經(jīng)跑通了,但是在我的客戶端請求服務(wù)器還是不行。
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: ws.iwwee.com:80" \
--header "Origin: http://ws.iwwee.com/:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://ws.iwwee.com/