Rate Limiting in iptables

iptables -A INPUT -p tcp –syn –dport 80 -m connlimit –connlimit-above 15 –connlimit-mask 32 -j REJECT –reject-with tcp-reset

Allowing Apache to see client ip from Behind a trusted proxy.

With high speed caching based on nginx, varnish or CDNs in general the client ip gets lost. All
IPs get reported as 127.0.0.1 since the proxy is making the socket request. Solution is two phased:

1) enable reporting the client IP to theย X-Forwarded-For header at the proxy or CDN.

This depends on the proxy will be covered in separate posts.

2) installing and configuring the mod_remoteip in Apache 2.

 

Project link L https://github.com/ttkzw/mod_remoteip-httpd22
mkdir /usr/local/src/mod_remoteip
cd /usr/local/src/mod_remoteip
wget https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/mod_remoteip.c
wget https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/mod_remoteip.conf
wget https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/Makefile

yum install httpd-devel
make
make install

Configuration in the Apache config file:

in /etc/httpd/conf/httpd.conf

# Load and configure mod_remoteip for Google PageSpeed Service
LoadModule remoteip_module /usr/lib64/httpd/modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For

service apache reload

voila ๐Ÿ™‚

How to test varnish vcl file

Unlike most other configuration systems varnish went with a compiled configuration so if there is a mistake all you get is :

 

Starting varnish HTTP accelerator: [FAILED]

To check what the problem is use the following :

varnishd -C -f default.vcl

varnishd -C -f default.vcl
Message from VCC-compiler:
Expected return action name.
(input Line 37 Pos 13)
return (hit_for_pass);
————############–
Running VCC-compiler failed, exit 1[root@MyHost1 varnish]# vim default.vcl
[root@MyHost1 varnish]# varnishd -C -f default.vcl
Message from VCC-compiler:
Invalid condition ‘&’ on numeric variable
only ‘==’, ‘!=’, ‘<‘, ‘>’, ‘<=’ and ‘>=’ are legal
(input Line 51 Pos 17)
if (obj.hits &gt; 0) {
—————-#——–

Rightly so the error shouts back at you with a # under it.

 

Very clear and to the point, the vcl I had was HTML’ed and replaced > with &gt;

 

That’s it..

nJoy ๐Ÿ˜‰

 

How To Install WordPress on Centos 6

About WordPress

WordPress is a free and open source website and blogging tool that uses php and MySQL. It was created in 2003 and has since then expanded to manage 22% of all the new websites created and has over 20,000 plugins to customize its functionality.

(more…)