Discover Centmin Mod today
Register Now

Nginx Limit connections edit in block?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Nov 8, 2014.

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    3:27 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Hi


    I just add this to the global nginx.conf file:
    Code:
    limit_conn_zone $binary_remote_addr zone=alpha:8m;
    and now i want to ad this to the domain config under the server {
    Code:
    limit_conn alpha 5;
    But on this file i have two blocks starting with server { :(
    On which one i must add it?

    Code:
    server {
      listen  80;
      server_name mydomain.com;
      return 301 $scheme://www.mydomain.com$request_uri;
      }
    
    server {
      server_name www.mydomain.com;
    
    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    54,368
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    11:27 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    3:27 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    My main problem is that when i try siege from another server and hit my server it is going very slow and i want to limit the requests so i can get an error or wait status after x connections :(

    So i can avoid others do this to my server ...

    Is this ok what i try to do for this scenario?
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,368
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    11:27 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    trial and error testing ;)
     
  5. pamamolf

    pamamolf Premium Member Premium Member

    4,077
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    3:27 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok i add it and test it but it is slow again.... :( and server load in 5 minutes goes up to 18 :(

    values that i use:

    main config:
    Code:
    http {
    ...
    limit_conn_zone $binary_remote_addr zone=alpha:8m;
    limit_req_zone $binary_remote_addr zone=delta:8m rate=80r/s;
    ...
    
    Domain config:
    Code:
    server {
    ...
    limit_conn alpha 15;
    limit_req zone=delta burst=100 nodelay;
    ...
    
    Is there any other way?
     
    Last edited: Nov 8, 2014