Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
- ./nginx/templates:/etc/nginx/templates:ro
- ./logs/nginx:/var/log/nginx
- ./nginx/certs:/etc/nginx/certs:ro
- ./nginx/scripts/fetch-cloudflare-ips.sh:/docker-entrypoint.d/40-fetch-cloudflare-ips.sh:ro
environment:
ORIGIN_NAME: hlds.run
TZ: Europe/Moscow
Expand Down
27 changes: 27 additions & 0 deletions nginx/scripts/fetch-cloudflare-ips.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# Пути к файлам, которые будут созданы
ALLOW_FILE="/etc/nginx/cloudflare_ips.conf"
REAL_IP_FILE="/etc/nginx/cloudflare_realip.conf"

echo "Fetching Cloudflare IPs..."

# Списки IP от Cloudflare
IPV4_URL="https://www.cloudflare.com/ips-v4"
IPV6_URL="https://www.cloudflare.com/ips-v6"

# Очищаем или создаем файлы
echo "# Cloudflare IP Ranges" > "$ALLOW_FILE"
echo "# Cloudflare Real IP Configuration" > "$REAL_IP_FILE"

# Скачиваем IP и формируем конфиги
for ip in $(wget -qO- $IPV4_URL) $(wget -qO- $IPV6_URL); do
echo "allow $ip;" >> "$ALLOW_FILE"
echo "set_real_ip_from $ip;" >> "$REAL_IP_FILE"
done

# Добавляем финальные директивы
echo "deny all;" >> "$ALLOW_FILE"
echo "real_ip_header CF-Connecting-IP;" >> "$REAL_IP_FILE"

echo "Cloudflare IPs updated successfully."
6 changes: 6 additions & 0 deletions nginx/templates/edge-https-proxy.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ server {
listen 443 ssl;
server_name *.${ORIGIN_NAME};

# Подключаем настройки Real IP, чтобы видеть IP пользователей в логах
include /etc/nginx/cloudflare_realip.conf;

# Ограничиваем доступ: разрешаем только Cloudflare
include /etc/nginx/cloudflare_ips.conf;

# SSL сертификаты (скопированы с origin / CF origin cert)
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
Expand Down