How did I block refferal spam traffic

Hi guys,

One of the my websites was under attack of an refferal spam.

How did I understand that? So simple. Just check your Google Analytics and you’ll see huge traffics that comes from some kind of spam sites.

But my situation was a little bit different because there was kind of the most populer sites like, or is one of the most popular news website of Turkey.

So it’s impossible to get organic traffic like this from these sites.
Firstly I tried to add some filters to GA. But it’s not a certain solution. It just disappears them on the statistics.

And my solution is blocking traffic which requests too much in a second. So I set limit for requests and just allowed max 2/sec per IP. Here is the nginx codes.

Add below code inside of the http{} blocks. You can find it in nginx.conf file.

limit_req_zone $binary_remote_addr zone=spam:10m rate=2r/s;

To assign which locations will be effected by this modification, use this:

I put it to main location “/” in server{} block.

location / {
limit_req zone=spam burst=5;