cloudflare CDN 사용하기 – log 에 접속자 IP가 아닌 Cloudflare IP 가 남는 현상

cloudflare ip

로그에 Cloudflare IP 가 수상하다

서비스를 운영하면서 서버 CPU 가 치솟을 때가 가끔 있다. 그럴때마다 혹시나 공격이..ㅠㅠ 하는 마음에 access.log 파일을 열어보는데, 그 시점에 항상 하나의 IP 가 접속을 반복적으로 시도하곤 한다. 근데 그 IP를 조사해보면 사용하고 있는 CDN 업체인 cloudflare  IP 더라. 그래서 서버 건들기도 무섭고, 좋은거겠거니 하고 뒀었다.

cloudflare ip
이 무시무시한 중복문구 반복되는 저 IP가 cloudflare 사의 IP 다.;;

근데 그런 현상이 반복적으로 일어나서 해당 업체 support 문서를 열어봤다.

링크: Why is CloudFlare attacking me? 라는 문서가 있었고, 어떤 모든 사용자가 cloudflare 를 거쳐서 서비스에 접속되기 때문에 실접속자가 아닌 cloudflare 의 IP가 남을 수 있다는 것이다. 긍까 공격이 들어와도 cloudflare IP로 보일 수 있다능..ㅠㅠ

그리고 아래와 같은 안내가 있다. 어떤 조치를 취해서 실 사용자 IP를 남길 수 있다고 한다.

1. You’re a CloudFlare customer with a domain on CloudFlare. Since we are a reverse proxy for sites using our service, our IPs are going to show in your server logs until you install something on your server to restore original visitor IP (mod_cloudflare for Apache servers, for example).

실접속자 IP를 남기기 (nginx)

진짜 접속자 IP를 확인하려면 추가로 어떤 조치를 취해야 한다고 안내가 되어있다. 안내되어 있는 링크(https://support.cloudflare.com/hc/en-us/sections/200805497-Restoring-Visitor-IPs)로 들어가면 여러가지 상황에 맞게 해결책이 제시되어 있다. 아파치를 사용했으면 쉽게 mod_cloudflare 를 설치하면 된다는데 나능 nginx 니까 nginx 설정을 변경해야 했음.

서버로 접속해서 nginx 설정파일 (nginx.conf 혹은 해당 server block 설정파일을 열어 http { 여기에 } 다음의 내용을 입력한다.

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 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 199.27.128.0/21;
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;

# use any of the following two
real_ip_header CF-Connecting-IP;
#real_ip_header X-Forwarded-For;

콘솔창을 열어 수정해도 되고 어려우면 FTP 프로그램을 통해 파일을 얻어온후 수정해도 된다. 근데 이 부분을 수정할라고 하는 사람이 콘솔로 수정하는 방법을 모르긴 힘들겠지.. 내가 이상한거지..ㅠㅠ

저장후에

# service nginx -t

로 수정한게 문제를 만들지 않았나 체크한 후

#service nginx restart

로 nginx 를 재시작한다.
그럼 이후에는 실 접속자 IP를 체크할 수 있다.

오늘의 교훈

이상하다 싶으면 찾아보자.
이상한게 맞다.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
모든 댓글 보기
0
생각을 나눠주시면 감사해요!x
()
x
Please enter Google Username or ID to start!
Example: clip360net or 116819034451508671546
Title
Caption
File name
Size
Alignment
Link to
  Open new windows
  Rel nofollow