Score:3

Nginx max_conns limit on multiple servers

br flag

If I have two server block in an Nginx and they both use the same upstream definitions. How would the max_conns limit work in this case?

I am assuming that the both server blocks will have a limit of 100 max connections and 90 keepalive. So in total, the following server blocks can have a total of 200 max_conns?

upstream example {
    server example.com:443 max_conns=100;
    keepalive 90;
}

 server {

            listen 1.1.1.1:80;
            server_name proxy.site.net;
            proxy_pass https://example
            proxy_bind 1.1.1.1 transparent;
 }
 
  server {

            listen 1.1.1.2:80;
            server_name proxy.site.net;
            proxy_pass https://example
            proxy_bind 1.1.1.2 transparent;
 }

My origin has a restriction of 100 concurrent connections per IP. So, I am splitting the traffic by using different IP for each server block. So, I want to achieve 100 concurrent connections per server block (or per public IP). How should I do that?

The purpose of having two server block is to be able to handle double amount of requests.

UPDATE:

The origin is a cloud provider which has put some hard limits on "connections per IP" in order to avoid overload. The origin says that every IP address can have up to 100 concurrent HTTP connections. If the same IP tries to establish connection number 101, the origin would throw an error. So, I want to use two IPs to have the capability to establish 200 concurrent connections to the origin at a time. Please help if you know what should be changed in my code to achieve it. –

UPDATE 2:

Below is the latest code that I am using to achieve 200 requests per second by using DNS round robin on my server's public IPs.

I have two different IPs listening in two server blocks and two different upstream names for those server blocks.

I am assuming now that If 100 people use the first IP in the DNS round-robin and the next 100 use the second IP then I will be able to serve 200 people concurrently. Even though my origin has a restriction of 100 connections per IP.

Please let me know if this code looks right?

upstream example {
    server example.com:443 max_conns=100;
    keepalive 90;
}

upstream example2 {
    server example.com:443 max_conns=100;
    keepalive 90;
}

 server {

            listen 1.1.1.1:80;
            server_name proxy.site.net;
            proxy_pass https://example
            proxy_bind 1.1.1.1 transparent;
 }
 
  server {

            listen 1.1.1.2:80;
            server_name proxy.site.net;
            proxy_pass https://example2
            proxy_bind 1.1.1.2 transparent;
 }
djdomi avatar
za flag
no they will have 100 as set above, but why do you want to use that at this point?
br flag
Just updated the question, please read the explanation below the sample code.
djdomi avatar
za flag
still the same since the target limit is set to 100. IMHO you did not change anything and a limit of 100 per single IP wouldn't be a usual use case, a single ip can eat up all your connections in that case, I believe still here is an x and y problem and you may need to tell us about the backend furthermore I believe you want to read the [manual](https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-http/)
br flag
The origin is a cloud provider which has put some hard limits on "connections per IP" in order to avoid overload. The origin says that every IP address can have up to 100 concurrent HTTP connections. If the same IP tries to establish connection number 101, the origin would throw an error. So, I want to use two IPs to have the capability to establish 200 concurrent connections to the origin at a time. Please help if you know what should be changed in my code to achieve it.
djdomi avatar
za flag
add this as an update not as comment
br flag
Please look at my "update 2" in the question and see if it can help me achieve more than 100 connections concurrently.
djdomi avatar
za flag
might work, do testload and verify, you don't need to specify a default port if https on 443 is used, ports only be needed in case it's not 80 for http or 443 for jttos
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.