conditionally disable keepalive for specific client IP address
April 22, 2015 06:00AM
Hello,

We're using nginx as a reverse proxy and we need to disable client keepalive for some specific client IP address.

I know that it can be done like this with apache:
SetEnvIf Remote_Addr "^10\.114\.18\." nokeepalive

but i have not found how to do that with nginx.
Thanks for helping.

Cyrille
Re: conditionally disable keepalive for specific client IP address
April 22, 2015 07:02AM
Something like;

map $remote_addr $kealtime {
default 30;
~^(192.168.123.*)$ 60;
~^(192.122.222.*)$ 0;
}

[...]

keepalive_timeout $kealtime;

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: conditionally disable keepalive for specific client IP address
April 24, 2015 06:40AM
I tried this but it seems to be forbiden:
nginx: [emerg] "keepalive_timeout" directive is not allowed here in...
It seems that we can't set keepalive_timeout with variable of within a if block: http://forum.nginx.org/read.php?2,254833,254880#msg-254880

Is there any other solution to this problem?
Re: conditionally disable keepalive for specific client IP address
April 24, 2015 07:02AM
Maybe Lua can do this,

set_by_lua $notused '
ngx.var.keepalive_timeout = ngx.var.kealtime;
';

https://github.com/chaoslawful/lua-nginx-module

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: conditionally disable keepalive for specific client IP address
April 24, 2015 07:08AM
This seems to work;

location / {
set $keepalive_timeout '';
root html;
[...]
set_by_lua $notused '
ngx.var.keepalive_timeout = ngx.var.kealtime;
';
}

---
nginx for Windows http://nginx-win.ecsds.eu/



Edited 1 time(s). Last edit at 04/24/2015 07:09AM by itpp2012.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 177
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready