npm,nginx에서 Cloudflare IP가 로그에 찍힐때 RealIP로 변경해주기
안녕하세요. 달소입니다.
Npm이나 Nginx와 같은 리버스 프록시를 사용하면서 클라우드 플레어를 사용할 경우
로그에 아래처럼 실제 클라이언트 IP가 아닌 클라우드 플레어 IP가 찍히게 됩니다
기본적으로 사용자가 직접 요청은 하지만 클라우드플레어 DNS Proxy를 한번 더 타서 발생하는 문제입니다 ㅠ
해결하기
해당 가상호스트.conf 나 npm의 Advanced에 아래처럼 설정값을 넣어주시면 됩니다.
IP범위는 공식홈페이지를 참고해주세요.
최종적으로는 아래와같은 설정을 넣어주시면됩니다.
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;
real_ip_header X-Forwarded-For;
그리고 nginx reload를 한번 해주시면 설정이 잘적용되신것을 확인할 수 있습니다.