R
R
Rokis2017-03-18 20:58:06
Nginx
Rokis, 2017-03-18 20:58:06

How to compactly write IP blocking rules in Nginx?

Hello.
There is a canvas with code in the /etc/nginx/sites-enabled/mysite.ru settings:

location /xmlrpc.php {
deny all;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
} }
location /wp-config.php {
allow 66.666.666.66;
allow 66.666.666.666;
deny all;
 location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
} }
location /wp-login.php {
allow 66.666.66.66;
allow 66.666.666.666;
deny all;
 location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
} }
location /wp-admin.php {
allow 66.666.666.66;
allow 66.666.66.666;
deny all;
 location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
} }

How to write down all this business compactly (preferably on several sites at once)? Without specifying location ~ \.php$ inside the directory that needs to be blocked - blocking by IP does not work (although the same thing is written at the beginning of the config). I think I'm somehow not connecting php.
Tell me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Zubkov, 2017-03-18
@zubkov_work

Make a php.conf file, write the php configuration there, and do include php.conf in the location. The same goes for access.

K
ky0, 2017-03-18
@ky0

Make a location with access lists, put all the rest inside it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question