CANNOT establish a normal connection when use Nginx to Load-Balance KCP traffic
The problem occurred is that the v2ray server treats my normal connection as 'replay attack'. I have several server running v2ray process, and I use Nginx to load-balance those traffic to each instance. All servers are configured to use KCP transfer method, but I can't connect under any condition. The v2ray log shows that "duplicated session id, possibly under replay attack", Nginx log shows "connection timeout". I think v2ray use session id distinguish each connection, and using Nginx to forward those packets should be OK. Furthermore, everything works fine if I use TCP transfer method. I haven't figured out any solution for this problem, so can anyone help me out ? Please see details below.
English: Please read the instruction and answer the following questions before submitting your issue. Thank you. Please answer all the questions with enough information. All issues not following this template will be closed immediately.
- What version of V2Ray are you using (If you deploy different version on server and client, please explicitly point out)?
The latest 3.25 version.
- What's your scenario of using V2Ray? E.g., Watching YouTube videos in Chrome via Socks/VMess proxy.
Just browsing websites.
- What did you see? (Please describe in detail, such as timeout, fake TLS certificate etc)
Connection Failed.
- What's your expectation?
Establish a normal connection
- Please attach your configuration file (Mask IP addresses before submit this issue). Just a simple KCP conf Server configuration:
{
"inbound": {
"port": 8976,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-34fg-8cda48b30811",
"alterId": 64
}
]
},
"streamSettings": {
"network": "kcp",
"kcpSettings": {
"mtu": 1350,
"tti": 20,
"uplinkCapacity": 5,
"downlinkCapacity": 100,
"congestion": true,
"readBufferSize": 2,
"writeBufferSize": 2,
"header": {
"type": "none"
}
}
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
}
}
Client configuration:
{
"inbound": {
"port": 1080,
"protocol": "socks",
"domainOverride": ["tls","http"],
"settings": {
"auth": "noauth"
}
},
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "serverip",
"port": 1000,
"users": [
{
"id": "b831381d-6324-4d53-34fg-8cda48b30811",
"alterId": 64
}
]
}
]
},
"streamSettings": {
"network": "kcp",
"kcpSettings": {
"mtu": 1350,
"tti": 20,
"uplinkCapacity": 5,
"downlinkCapacity": 100,
"congestion": true,
"readBufferSize": 2,
"writeBufferSize": 2,
"header": {
"type": "none"
}
}
}
}
}
-
Please attach error logs, especially the bottom lines if the file is large. Error log file is usually at
/var/log/v2ray/error.logon Linux.// Please attach your server error log here. [Info] [3244914456] App|Proxyman|Inbound: connection ends > Proxy|VMess|Inbound: invalid request from 192.168.1.100:54115 > Proxy|VMess|Encoding: duplicated session id, possibly under replay attack
-
Please attach access log. Access log is usually at '/var/log/v2ray/access.log' on Linux.
192.168.1.103:8976 rejected Proxy|VMess|Encoding: duplicated session id, possibly under replay attack
Please review your issue before submitting.
- Other configurations (such as Nginx) and logs. This is nginx stream conf
stream {
server{
listen [::]:1000 udp ipv6only=off;
proxy_pass v2;
}
upstream v2 {
least_conn;
server 192.168.1.101:8976;
server 192.168.1.102:8976;
server 192.168.1.103:8976;
}
}
This is nginx error log: upstream timeout
9) If V2Ray doesn't run, please attach output from --test.
The command is usually /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json, but may vary according to your scenario.
- If V2Ray service doesn't run, please attach journal log.
Usual command is journalctl -u v2ray.
Nginx 的 load balancing strategy 应该要根据客户端 IP 来,比如
hash $remote_addr:$remote_port;
因为 UDP 是无状态的,不能用 least_conn 之类的strategy.
OK I see. Then I edit my nginx config like:
stream {
server{
listen [::]:1000 udp ipv6only=off;
proxy_pass v2;
}
upstream v2 {
hash $remote_addr:$remote_port;
server 192.168.1.101:8976;
server 192.168.1.102:8976;
server 192.168.1.103:8976;
}
}
However I still got many "duplicated session id" errors, so what's the problem?
Not sure. Probably your sever is really under replay attack.
I’m closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on for so long, then it seems no one has the time to implement this.
Please reopen if you still encounter this issue with the latest stable version. You can also contribute directly by providing a patch – see the developer manual. :)
Thank you!