We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Rate-limit nginx to one connection per IP? (downloads)
Rate-limit nginx to one connection per IP? (downloads)
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!
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!
Re: Rate-limit nginx to one connection per IP? (downloads)
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:
add:
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:
Ensure if here is no errors: nginx -t
And reload nginx: service reload nginx
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;
Code: Select all
# Ratelimit zone
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
/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;
}
And reload nginx: service reload nginx
Re: Rate-limit nginx to one connection per IP? (downloads)
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 loldreiggy wrote: ↑Thu Apr 18, 2019 8:41 pmHere 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:add:Code: Select all
# Wildcard include include /etc/nginx/conf.d/*.conf;
Then in custom vhost nginx config you should create something like this:Code: Select all
# Ratelimit zone limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
/home/admin/conf/web/nginx.$DOMAIN.conf-custom and /home/admin/conf/web/snginx.$DOMAIN.conf-custom
add:Ensure if here is no errors: nginx -tCode: Select all
location /downloads/ { limit_req zone=mylimit; proxy_pass http://my_upstream; }
And reload nginx: service reload nginx
Re: Rate-limit nginx to one connection per IP? (downloads)
Here is a good tutorial about nginx location blocks. Try to read and understand.
https://www.digitalocean.com/community/ ... algorithms
https://www.digitalocean.com/community/ ... algorithms