Спойлер

суббота, 22 января 2022 г.

Получение реальных ip подключений через Remote_ip Apache2 + cloudflare

 1. Проверяем установлен ли модуль remoteip и включен:
sudo a2enmod remoteip   
2. Обновляем конфигурацию апача и добавляем RemoteIPHeader CF-Connecting-IP
обычно лежит по след. пути: /etc/apache2/sites-available/000-default.conf

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
RemoteIPHeader CF-Connecting-IP
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

3. Добавляем трастовые IP (trusted proxy addresses) в файле /etc/apache2/conf-available/remoteip.conf  или может лежать в папке mods-available (если файла нет, создаем его):

RemoteIPHeader CF-Connecting-IP
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 104.16.0.0/12
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2606:4700::/32
RemoteIPTrustedProxy 2803:f800::/32
RemoteIPTrustedProxy 2405:b500::/32
RemoteIPTrustedProxy 2405:8100::/32
RemoteIPTrustedProxy 2a06:98c0::/29
RemoteIPTrustedProxy 2c0f:f248::/32
Добавлять IP Cloudflare необязательно!

4. Активируем все новые конфигурации
sudo a2enconf remoteip
Enabling conf remoteip.
To activate the new configuration, you need to run:
    service apache2 reload
5. Тестируем новую конфигурацию Apache
sudo apache2ctl configtest
Syntax OK
6. Делаем рестарт Apache.
sudo systemctl restart apache2

7.Добавляем нужные правила в htaccess, например, блокируем запросы к xmlrpc.php

# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
</Files>

Комментариев нет:

Отправить комментарий