Answer the question
In order to leave comments, you need to log in
How to deny access to a site based on the criterion of belonging to a country?
Greetings, %username%.
Input :
There is a certain resource (with access for clients only via http). The resource stores various, including rather large files (conditionally - distributions, as on http://mirror.yandex.ru/) . Used hosting service (not VDS), on board Apache1.3 and php5.3. The file listing is output by Apache. The last time the number of requests to the server has greatly increased, and it began to fail to withstand the loads. On average - 3..10 requests per second.
Required :
Restrict access. Deny access to everyone, say, except for the "RF" and neighboring countries (a lot of requests have become just "because of the hillock").
Suggested Solution :
Use php to determine the country of the client (implemented) + "transparently resolve" access to files. Redirect all requests to php:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^\.]+)$ check.php?url=$1 [L,QSA,NC]
</IfModule>
Answer the question
In order to leave comments, you need to log in
I'm sorry, I'm not sure I know how to do this using bare apache and .htaccess, but why don't you use nginx built with one of the many GeoIP modules?
Firstly, nginx handles static better, and it is likely that the load will drop immediately after the introduction of nginxa as a front, and there will be no such urgent need to cut users by region, and secondly, this is implemented quite simply in nginx:
For example, using the geoip2 module, you can use the standard if construct in nginx locations to compare the value of the $region variable with the ones you need to prohibit / allow.
I apologize if you think my answer is offtopic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question