0

Got nginx serving several big files. Users get access through basic authentication. htpasswd I want to curtail simultaneous download of files to 5 connections max PER USER. There are more than 1 user getting access through 1 IP address so it is not possible to do it by IP.

I've tried following:

map "$remote_user" $num {
     default 5
     }

server {
 location /source {
   root /home/frog/source/;
   auth_basic "Login";
   auth_basic_user_file /home/frog/.htpasswd;
   set $limit_conn $num;
  }

But it won't limit it. I still cat open more than five connections simultaneously. Help!

1 Answers1

0

After some light reading it worked out like this:

limit_conn_zone $remote_user zone=limit:10m;

server {
 location /source {
   root /home/frog/source/;
   auth_basic "Login";
   auth_basic_user_file /home/frog/.htpasswd;
   limit_conn limit 5;
  }

Need to set limit_conn_zone $remote_user zone=limit:10m; outside server block and then add limit_conn limit 5; inside server block

Now each user can open no more than 5 simultaneous connections.