Nginx反代到workman,没有数据返回

kajweb
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"

但是直接访问不经过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个进程对外提供服务
$ws_worker->count = 4;
2479 3 0
3个回答

kajweb

nginx version: nginx/1.12.2

经过测试,workman能收到请求,但是无法返回到nginx。

环境:套路云
端口:50000
出入规则已经开放

  • 暂无评论
xiuwang
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;
  }

}

我用的类似这样的配置,没有问题

  • kajweb 2020-06-17

    刚刚换成您这个配置了,但是还是不行。在服务器使用curl已经跑通了,但是在我的客户端请求服务器还是不行。

    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/
  • kajweb 2020-06-17

    但是直接访问http协议,反代成功。但是使用ws协议,就没有返回。

kajweb

好像解决了,是proxy_buffering的问题。

  • 暂无评论
年代过于久远,无法发表回答
×
🔝