# Question about allowing a percentage of traffic

**URL:** <https://www.ruby-forum.com/t/question-about-allowing-a-percentage-of-traffic/218120>\
**Category:** NGINX\
**Created:** [March 21, 2012, 7:45pm UTC](https://www.ruby-forum.com/t/question-about-allowing-a-percentage-of-traffic/218120 "2012-03-21T19:45:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 21, 2012, 7:45pm UTC](https://www.ruby-forum.com/t/question-about-allowing-a-percentage-of-traffic/218120/1 "2012-03-21T19:45:16Z")

</div>

This is about traffic control, in the case we get slammed by heavier  
traffic than expected we want to be able to gracefully only allow part  
of the users’ requests to come through.

In my current nginx config, I have a white list based on a  
$http\_x\_user\_id header in the request and only allow traffic from those  
users.

The way I did it was a condition in the location / block:

if ( $http\_x\_user\_id !~ (THE\_WHITE\_LIST\_OF\_IDs) ) {  
return 503;  
}

(We can control the white list dynamically and re-render the config with  
Chef.)

What I also need to do is to allow a certain percentage of requests from  
users whose id is not in the white list. For example, I need to be able  
to allow 30% of users in addition to those in the white list to get  
access. Based on my limited knowledge on nginx, I have no idea on what’s  
the best way to do it.

Any insights?

Thanks a lot.

Posted at Nginx Forum:

> **[Question about allowing a percentage of traffic](https://forum.nginx.org/read.php?2,224190,224190#msg-224190)**
>
> This is about traffic control, in the case we get slammed by heavier traffic than expected we want to be able to gracefully only allow part of the users' requests to come through. In my current nginx config, I have a white list based on a...

---

<div class="post-metadata">

**Author:** ![spacerobot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@spacerobot](https://www.ruby-forum.com/u/spacerobot)\
**Post date:** [March 21, 2012, 8:11pm UTC](https://www.ruby-forum.com/t/question-about-allowing-a-percentage-of-traffic/218120/2 "2012-03-21T20:11:27Z")

</div>

On Wednesday 21 March 2012 22:44:26 spacerobot wrote:

> if ( $http\_x\_user\_id !~ (THE\_WHITE\_LIST\_OF\_IDs) ) {  
> the best way to do it.
> 
> Any insights?

Perhaps the split clients module will be suitable for you:

> **[Module ngx\_http\_split\_clients\_module](http://nginx.org/en/docs/http/ngx_http_split_clients_module.html)**

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![spacerobot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@spacerobot](https://www.ruby-forum.com/u/spacerobot)\
**Post date:** [March 21, 2012, 8:14pm UTC](https://www.ruby-forum.com/t/question-about-allowing-a-percentage-of-traffic/218120/3 "2012-03-21T20:14:35Z")

</div>

> What I also need to do is to allow a certain percentage of requests from  
> users whose id is not in the white list. For example, I need to be able  
> to allow 30% of users in addition to those in the white list to get  
> access. Based on my limited knowledge on nginx, I have no idea on what’s  
> the best way to do it.
> 
> Any insights?

Embedded perl can help.

---

<div class="post-metadata">

**Author:** ![spacerobot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@spacerobot](https://www.ruby-forum.com/u/spacerobot)\
**Post date:** [March 23, 2012, 8:42pm UTC](https://www.ruby-forum.com/t/question-about-allowing-a-percentage-of-traffic/218120/4 "2012-03-23T20:42:12Z")

</div>

Thanks guys, the split\_clients module worked.

Posted at Nginx Forum:

> **[Re: Question about allowing a percentage of traffic](https://forum.nginx.org/read.php?2,224190,224296#msg-224296)**
>
> This is about traffic control, in the case we get slammed by heavier traffic than expected we want to be able to gracefully only allow part of the users' requests to come through. In my current nginx config, I have a white list based on a...
