nginx 配置反向代理 UDP 流量(minecraft 应用程序)-90 条消息太长

nginx 配置反向代理 UDP 流量(minecraft 应用程序)-90 条消息太长

尝试代理 udp 流量。nginx 不会抛出任何有关配置的错误。客户端连接直到一半(它说它可以到达终端服务器),但连接随后卡住并最终因超时而关闭。

nginx版本:1.21.3 操作系统:Ubuntu 18.04

nginx.conf:

worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

worker_rlimit_nofile 30000;

events {
    worker_connections 30000;
    multi_accept on;
}

stream{
server {
    listen       *:4800-4899 udp;
    proxy_pass   217.178.x.x:$server_port;
}
}

错误日志:

2213#2213: *3 recv() failed (90: Message too long) while proxying and reading from upstream, udp client: 49.98.x.x, server: 66.42.x.x:4801, upstream: "217.178.x.x:4801", bytes from/to client:1464/0, bytes from/to upstream:0/1464

49.98.xx:客户端IP 66.42.xx:代理IP 217.178.xx:端服务器IP

ip 输出

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 56:00:03:95:cc:59 brd ff:ff:ff:ff:ff:ff
    inet 66.42.x.x/23 brd 66.42.x.255 scope global dynamic enp1s0
       valid_lft 57402sec preferred_lft 57402sec
    inet6 fe80::5400:3ff:fe95:[xxx]/64 scope link 
       valid_lft forever preferred_lft forever

知道哪里出了问题吗?有人能看出配置有什么问题吗?

谢谢

答案1

问题“90:消息太长”可能与 EMSGSIZE 错误 ( If the message is too long to pass atomically through the underlying protocol, the error EMSGSIZE is returned, and the message is not transmitted) 有关,在这种情况下,您可以尝试通过增加套接字发送缓冲区的大小来解决它。以下参数具有标准值:

net.core.wmem_default = 212992
net.core.wmem_max = 212992

您可以使用以下命令检查服务器上的当前值:

sysctl -a | grep "net.core.wmem"

为了测试,使用以下命令,您可以设置例如以下值:

sysctl -w net.core.wmem_default = 9999999
sysctl -w net.core.wmem_max = 9999999
echo "net.core.wmem_default = 9999999
net.core.wmem_max = 9999999 ">> /etc/sysctl.conf

接下来,检查它们是否正确应用(现在必须是 9999999):

sysctl -a | grep "net.core.wmem"

并尝试重现该问题。

相关内容