k8w / tsrpc

A TypeScript RPC framework, with runtime type checking and serialization, support both HTTP and WebSocket. It is very suitable for website / APP / games, and absolutely comfortable to full-stack TypeScript developers.
MIT License
1.9k stars 203 forks source link

nginx配置websocket报错 #37

Closed wmHappy closed 2 years ago

wmHappy commented 2 years ago

Invalid request buffer, please check the version of service proto.

k8w commented 2 years ago

配置文件贴一下

wmHappy commented 2 years ago

user root;

worker_processes 4;

error_log logs/error.log;

error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events { worker_connections 102400; accept_mutex on; multi_accept on;

use epoll;

}

http { include mime.types; default_type application/octet-stream;

access_log off; sendfile on; tcp_nopush on;

keepalive_timeout 55;

tcp_nodelay on; client_header_buffer_size 4k; client_body_buffer_size 512k; open_file_cache max=102400 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 1; client_header_timeout 15; client_body_timeout 15; reset_timedout_connection on; send_timeout 15; server_tokens off; client_max_body_size 50m;

proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k;

gzip on; gzip_min_length 1k; gzip_buffers 4 16k;

gzip_http_version 1.0;

gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary off; gzip_disable "MSIE [1-6]."; map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; server_name localhost;

static file

location /{
   root "D:/Program Files/Nginx/nginx-1.16.1/html/";
   index index.html;
   add_header Access-Control-Allow-Origin *;
   add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
       add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
}
location /niudu{  
    proxy_pass http://localhost:8887;
}
location /fish{  
    proxy_pass http://localhost:8890;
}
location /userApi{
    proxy_pass http://localhost:8080;
}
location /matchApi{
    proxy_pass http://localhost:8081;
}
location /roomApi{
    proxy_pass http://localhost:8082;
}
location /user {
        proxy_pass   http://127.0.0.1:3001; 
        proxy_http_version 1.1;
    proxy_read_timeout   3600s;
    proxy_redirect off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Connection keep-alive;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    }
location /match {
        proxy_pass   http://127.0.0.1:3000; 
        proxy_http_version 1.1;
    proxy_read_timeout   3600s;
    proxy_redirect off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Connection keep-alive;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
location /room {
        proxy_pass   http://127.0.0.1:3002;
        proxy_http_version 1.1;
    proxy_read_timeout   3600s;
    proxy_redirect off;
    proxy_set_header Connection keep-alive;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
error_page   500 502 503 504  /50x.html;
location = /50x.html {
  root   html;
}
location ~* \.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
  ssi on;
  ssi_silent_errors on;
  root "D:/Program Files/Nginx/nginx-1.16.1/html/";
  add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
  add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
  #index index1.html;
  #cache
  expires 7d;
}

} }

wmHappy commented 2 years ago
<17816> 2022-10-19 19:46:10 [INFO] ::1 #1275 [Api:matchAdmin/RoomServerJoin] [ApiReq] { serverUrl: 'ws://127.0.0.1/match' } <17816> 2022-10-19 19:46:10 [INFO] RS|ws://127.0.0.1/match TSRPC WebSocket Client : ws://127.0.0.1/match <17816> 2022-10-19 19:46:10 [INFO] RS|ws://127.0.0.1/match Start connecting ws://127.0.0.1/match... <17816> 2022-10-19 19:46:10 [INFO] RS|ws://127.0.0.1/match WebSocket connection to server successful <17816> 2022-10-19 19:46:10 [INFO] RS|ws://127.0.0.1/match [ApiReq] #1 roomAdmin/Auth { type: 'MatchServer', token: '' } 匹配服务有连接被断开 <17816> 2022-10-19 19:46:10 [INFO] RS|ws://127.0.0.1/match Lost connection to ws://127.0.0.1/match code=1000 reason=Invalid request buffer, please check the version of service proto. <17816> 2022-10-19 19:46:10 [ERROR] RS|ws://127.0.0.1/match [ApiErr] #1 roomAdmin/Auth TsrpcError { message: 'Invalid request buffer, please check the version of service proto.', type: 'NetworkError', code: 'LOST_CONN' } <17816> 2022-10-19 19:46:10 [ERROR] ::1 #1275 [Api:matchAdmin/RoomServerJoin] [ApiErr] 18ms TsrpcError { message: 'Invalid request buffer, please check the version of service proto.', type: 'NetworkError', code: 'LOST_CONN' } req= { serverUrl: 'ws://127.0.0.1/match' } 这个是其中的一个打印日志
wmHappy commented 2 years ago

不好意思 问题找到了 是websocket连接的url地址 和发送的消息协议 不是同一个 也就是连接的匹配服务url 然后用了房间服务的serviceProto 发送了房间服务的消息内容 感谢作者您写的开源tsrpc 用起来很方便