Jump to content


Photo

Nginx limit download speed


  • Please log in to reply
4 replies to this topic

#1 plexman OFFLINE  

plexman

    Advanced Member

  • Members
  • 330 posts
  • Local time: 04:56 PM
  • LocationSpain

Posted 20 March 2018 - 01:38 PM

Emby has the amazing feature to allow users to download content. This is pretty cool but when an user downloads content it uses all available bandwith of your server. Adding this location block in your nginx config will limit the speed of the download and the number of simultaneous downloads per IP address.

# Add this outside of you server block
limit_conn_zone $binary_remote_addr zone=addr:10m;

# Bandwith limit (inside server block)
location ~ /emby/Items/(.*)/Download$ {
       # Send traffic to the backend
       proxy_pass http://localhost:8096;
       proxy_set_header Range $http_range;
       proxy_set_header If-Range $http_if_range;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header Host $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

       # Send websocket data to the backend aswell
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";

       limit_rate 1700k; # Speed limit (here is on kb/s)
       limit_conn addr 3; # Number of simultaneous downloads per IP
       limit_conn_status 460;
       proxy_buffering on;
}

# Error page
error_page 460 http://your-page-telling-your-limit/;

So in this case 3 parallel downloads at 1,7 Mb/s (note that Nginx takes speed values, not bandwith) are allowed, the "460 error" (you can specify whatever error number you want) redirects the user to a custom page when he tries to download the 4th item. In my case I have a webpage telling something like "Ops... You are downloading too much... Wait until your current downloads are completed"

 

Hope it helps somebody!

 

References:

https://emby.media/c...-reverse-proxy/

https://www.nginx.co...limiting-nginx/


Edited by plexman, 17 September 2018 - 01:46 PM.

  • Swynol, Spaceboy, pir8radio and 4 others like this

#2 mastrmind11 OFFLINE  

mastrmind11

    Advanced Member

  • Members
  • 2638 posts
  • Local time: 10:56 AM
  • LocationLong Island, NY

Posted 20 March 2018 - 04:44 PM

well done.


  • plexman likes this

#3 Jdiesel ONLINE  

Jdiesel

    Advanced Member

  • Members
  • 2616 posts
  • Local time: 08:56 AM
  • LocationRegina, SK

Posted 20 March 2018 - 05:01 PM

Very nice


  • plexman likes this

#4 plexman OFFLINE  

plexman

    Advanced Member

  • Members
  • 330 posts
  • Local time: 04:56 PM
  • LocationSpain

Posted 17 September 2018 - 01:47 PM

I've edited the location regex with a cleaner one.


  • Maximus Naxsus likes this

#5 Justy OFFLINE  

Justy

    Newbie

  • Members
  • 1 posts
  • Local time: 04:56 PM
  • LocationGermany

Posted 25 April 2019 - 04:21 PM

Hi,

 

I'm following this community since almost one year. It's amazing and you can find many answers to almost every question.

But now I'm stuck.

 

Is this config still working with actual emby 4.1.0.26? i put it in my nginx, but does not seem to have any effect.

Thanks in advance






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users