Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Rate-limit nginx to one connection per IP? (downloads)

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
4 posts • Page 1 of 1
VENAXIS
Posts: 13
Joined: Sat Oct 10, 2015 11:10 am

Rate-limit nginx to one connection per IP? (downloads)
  • Quote

Post by VENAXIS » Sun Apr 14, 2019 8:58 pm

Hello,

I was wondering how would I achieve this through nginx? I have read the nginx wiki but still haven't been able to achieve the desired result.

Is there a way to rate-limit downloads (for all files and subfolders inside of a specific directory) to one file at a time per IP, and also to downgrade to a specific download speed after a specific quota is reached in a day? I saw that all of this was mentioned in the wiki and did try to apply it for days lol but to no avail.

If it's too much trouble, at least I'd want to be able to limit it to one connection per ip and to a specific fixed speed. Your help is greatly appreciated!
Top

dreiggy
Posts: 154
Joined: Thu May 17, 2018 8:05 pm
Contact:
Contact dreiggy
Skype

Os: CentOS 6x
Web: apache + nginx
Re: Rate-limit nginx to one connection per IP? (downloads)
  • Quote

Post by dreiggy » Thu Apr 18, 2019 8:41 pm

Here I scrapped something fast, but not tested... ;) So try to test it before do anything on production...
More info: https://www.nginx.com/blog/rate-limiting-nginx/

/etc/nginx/nginx.conf before:

Code: Select all

    # Wildcard include
    include             /etc/nginx/conf.d/*.conf;
add:

Code: Select all

    # Ratelimit zone
    limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
Then in custom vhost nginx config you should create something like this:
/home/admin/conf/web/nginx.$DOMAIN.conf-custom and /home/admin/conf/web/snginx.$DOMAIN.conf-custom

add:

Code: Select all

    location /downloads/ {
        limit_req zone=mylimit;
        
        proxy_pass http://my_upstream;
    }
Ensure if here is no errors: nginx -t
And reload nginx: service reload nginx
Top

VENAXIS
Posts: 13
Joined: Sat Oct 10, 2015 11:10 am

Re: Rate-limit nginx to one connection per IP? (downloads)
  • Quote

Post by VENAXIS » Fri Apr 26, 2019 11:10 pm

dreiggy wrote: ↑
Thu Apr 18, 2019 8:41 pm
Here I scrapped something fast, but not tested... ;) So try to test it before do anything on production...
More info: https://www.nginx.com/blog/rate-limiting-nginx/

/etc/nginx/nginx.conf before:

Code: Select all

    # Wildcard include
    include             /etc/nginx/conf.d/*.conf;
add:

Code: Select all

    # Ratelimit zone
    limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
Then in custom vhost nginx config you should create something like this:
/home/admin/conf/web/nginx.$DOMAIN.conf-custom and /home/admin/conf/web/snginx.$DOMAIN.conf-custom

add:

Code: Select all

    location /downloads/ {
        limit_req zone=mylimit;
        
        proxy_pass http://my_upstream;
    }
Ensure if here is no errors: nginx -t
And reload nginx: service reload nginx
Hey! Thanks. However I tried a few very similar mothods but I did not get it to work. Do you know how the path for nginx works with a vesta installation (download location)? Let's say it was inside one of my website's public html. I tried full paths before and didn't work. Also the "mylimit", what kind of values does it respond to? Also the proxy_pass. Excuse my ignorance, nginx confuses me and I read the documentation so many times lol
Top

dreiggy
Posts: 154
Joined: Thu May 17, 2018 8:05 pm
Contact:
Contact dreiggy
Skype

Os: CentOS 6x
Web: apache + nginx
Re: Rate-limit nginx to one connection per IP? (downloads)
  • Quote

Post by dreiggy » Mon Apr 29, 2019 3:43 pm

Here is a good tutorial about nginx location blocks. Try to read and understand.
https://www.digitalocean.com/community/ ... algorithms
Top


Post Reply
  • Print view

4 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password