I am hosting my website on an OVH "pro" hosting offer.
For the last few weeks/months, I have experienced massive, unwanted traffic that either crashes my website, or triggers deactivation. The visits are coming from many countries (Vietnam, Brazil, India etc), and the IP is unique for each visit. As such, simple methods like adding "deny" commands in the .htaccess file won't work. For example last night there was 4M visits around 1am (see screenshot of my stats).
OVH won't help. I am not sure what I can do at my level, i.e. in PHP code or .htaccess file. Should this not be done at infrastruture level? Using CloudFlare or similar?
I am getting quite desperate, any advice would be most welcome.
I recently helped someone who had a problem similar to yours, and adding a small PHP script (via an include at the very beginning of the index.php file) solved the issue.
Here is the solution that successfully bans the IP addresses:
I have tried your first suggestion, using GEOIP_COUNTRY_CODE, but I am not sure it is working, as I have tried banning the UK (I am in the UK, but most of my visitors are in France, so it's safe for testing purposes), and I can still access the site. I think GeoIP is active, I have created this test file to check, and it says GB for me when I visit:
You can sign up for Cloudflare and once your domain is configured, go to Security > WAF.
You can also create a custom rule. For example, to block traffic from countries where you have no customers, select "Country" and "Equals" and choose the ones you want to block.
Finally, I recommend you enable the Under Attack Protection Mode. This shows a verification page to visitors, stopping malicious bots.
Once your traffic goes through Cloudflare, make sure OVH only sees traffic from Cloudflare's IPs. You can find the list of IPs in Cloudflare's documentation and restrict access to your hosting for security.
I am not sure I understand your response... I am only trying part 1 in your solution for now, i.e. using GEOIP_COUNTRY_CODE in the .htaccess file... And I am noting that even though I have banned GB, I can still access the site. Am I misunderstanding something? Thanks
Yes, Cloudflare is free to start protecting your site. Its Free plan includes CDN, SSL, DNS, basic DDoS protection and a WAF, which is usually enough for personal sites, small projects, or to mitigate attacks like the one you're experiencing
Cloudflare > security > bot protection > on
Or also security rule > "(not ip.src.continent in {"EU" "NA"} and not cf.client.bot)"
Potentially block an entire series of user agents, e.g.:
(http.user_agent contains "Go-http-client") or (http.user_agent eq "") or (http.user_agent contains "l9scan") or (http.user_agent contains "Wget") or (http.user_agent contains "curl") or (http.user_agent contains "python") or (http.user_agent contains "Scrapy") or (http.user_agent contains "perl") or (http.user_agent contains "PowerShell") or (http.user_agent contains "Java") or (http.user_agent contains "PHP") or (http.user_agent contains "aiohttp") or (http.user_agent contains "ImagesiftBot") or (http.user_agent contains "GuzzleHttp") or (http.user_agent contains "libredtail-http")
Right, after months of saying "we can't help you with this, pay for your own support", OVH have shared a link to their doc, that shows me how to block specific countries using GEOIP_COUNTRY_CODE, and it seems to work, since I have briefly managed to block myself here in the UK.
So simple... now let's wait a few days, to see if it actually works again real threats.
Thank you all for your messages, great community, it's my first time here I would have never queried OVH about GEOIP_COUNTRY_CODE and obtained the links above without your message @Gaston
I am not sure... most AI summaries seem to agree that "Yes, country code blocking via GEOIP_COUNTRY_CODE affects IPv6 requests, but only if your server uses an IPv6-compatible GeoIP database and the software module is configured to process IPv6 addresses."
So it will depend on the OVH setup.
I will try and keep an eye on my HTTP logs, but the vast majority of problematic visits are IP v4, so I am not sure I will find the answer to your question, sorry.
I haven't yet, but I will... I have limited time at the moment, so wanted to try the simple fix first... we'll see if it works. But I want to learn Cloudflare anyway, for my own benefit and interest, so will do that for sure... thanks