How to limit the number of connections to ports in nginx tcp forwarding?

TCP forwarding, how to limit the number of port connections?

it is not valid to use limit $server_port here.

error report:

nginx: [emerg] unsupported key "$server_port", use $binary_remote_addr
stream {

   limit_conn_zone  $server_port zone=perserver:100m; //

   upstream test {
        server 192.168.1.2:1111 max_fails=2 fail_timeout=5s;
    }


    server {
        listen        1111;
        proxy_pass    test;
        proxy_timeout 40s;
        proxy_connect_timeout 16s;
        limit_conn perserver 20;
    }
}
Mar.10,2022
Menu