클라우드플레어 nginx 연동
자바나 php, 파이썬으로 리퍼러 만들어 놓으면 실제 IP 가 아닌, 클라우드플레어의 IP 가 기록 된다.
이걸 실제 IP 로 등록 하기 위해서는 nginx 에 클라우드 플레어의 IP 대역폭을 등록하고 치환 시켜야 된다.
vi /etc/nginx/conf.d/cloudflare-realip.conf
파일 생성 후
# Cloudflare IPv4
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
# Cloudflare IPv6
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
# Real visitor IP
real_ip_header CF-Connecting-IP;
그대로 등록.
sudo nginx -t
syntax is ok
test is successful
sudo systemctl reload nginx
vi test_visit.php 파일 만들고 테스트.
echo 'REMOTE_ADDR: ' . ($_SERVER['REMOTE_ADDR'] ?? '') . '<br>';
echo 'CF_CONNECTING_IP: ' . ($_SERVER['HTTP_CF_CONNECTING_IP'] ?? '') . '<br>';
echo 'HTTP_X_FORWARDED_FOR: ' . ($_SERVER['HTTP_X_FORWARDED_FOR'] ?? '') . '<br>';
여기서는 실제 IP 주소가 찍혀야 되고,
nginx -T | grep -E 'set_real_ip_from|real_ip_header'
테스트 후에
윈도우 shell 같은 거에서 ping xxxx.com 같은 본인 도메인에 접속
172....... 이런식의 클라우드플레어가 찍히면 성공.
'Server > Nginx' 카테고리의 다른 글
| php codeigniter nginx (0) | 2023.09.17 |
|---|---|
| letsencrypt 보안서버 설치 및 갱신 (0) | 2020.07.01 |
| url에서 www를 제거하기 위한 nginx rewrite 설정 (0) | 2017.10.23 |
| nginx "An error occurred." (0) | 2016.08.18 |
| 코드이그나이터 Ninx 에서 사용하기 (0) | 2015.12.04 |