1. 환경
- CF + ELB + EC2(nginx)
2. 문제
- 클라이언트 ip주소에 ELB, CloudFront IP들이 덧씌워진다. (ex : 1.1.1.1, 2.2.2.2, 3.3.3.3)
- ip deny or was에서 처리할때 문제가 발생한다.
3. 해결방법
1) nginx real ip 기능(참고자료)
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
- 위 방법은 또 다른 문제를 발생 시킬 수 있음.
- 아래 curl을 날려보자.
- nginx 로그를 켜서 보게되면 사용자 ip가 1.2.3.4로 나오게 될 겁니다.
2) nginx real ip + make-nginx-real-ip-conf(소스링크) 사용
- make-nginx-real-ip-conf로 만든 conf 파일을 include 시킨다. 끝!
- 아래는 make-nginx-real-ip-conf 프로그램으로 생성한 파일입니다.
#Make at 20170907162608
#your ELB IP
set_real_ip_from 110.0.0.0/8;
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 192.168.0.0/16;
#AWS CloudFront IP/CIDR range
set_real_ip_from 13.113.203.0/24;
set_real_ip_from 13.124.199.0/24;
set_real_ip_from 13.228.69.0/24;
set_real_ip_from 13.32.0.0/15;
set_real_ip_from 13.54.63.128/26;
set_real_ip_from 13.59.250.0/26;
set_real_ip_from 204.246.164.0/22;
set_real_ip_from 204.246.168.0/22;
set_real_ip_from 204.246.174.0/23;
set_real_ip_from 204.246.176.0/20;
set_real_ip_from 205.251.192.0/19;
set_real_ip_from 205.251.249.0/24;
set_real_ip_from 205.251.250.0/23;
set_real_ip_from 205.251.252.0/23;
set_real_ip_from 205.251.254.0/24;
set_real_ip_from 216.137.32.0/19;
set_real_ip_from 34.195.252.0/24;
set_real_ip_from 34.226.14.0/24;
set_real_ip_from 35.158.136.0/24;
set_real_ip_from 35.162.63.192/26;
set_real_ip_from 35.167.191.128/26;
set_real_ip_from 52.15.127.128/26;
set_real_ip_from 52.199.127.192/26;
set_real_ip_from 52.212.248.0/26;
set_real_ip_from 52.220.191.0/26;
set_real_ip_from 52.222.128.0/17;
set_real_ip_from 52.46.0.0/18;
set_real_ip_from 52.52.191.128/26;
set_real_ip_from 52.56.127.0/25;
set_real_ip_from 52.57.254.0/24;
set_real_ip_from 52.66.194.128/26;
set_real_ip_from 52.78.247.128/26;
set_real_ip_from 52.84.0.0/15;
set_real_ip_from 54.182.0.0/16;
set_real_ip_from 54.192.0.0/16;
set_real_ip_from 54.230.0.0/16;
set_real_ip_from 54.233.255.128/26;
set_real_ip_from 54.239.128.0/18;
set_real_ip_from 54.239.192.0/19;
set_real_ip_from 54.240.128.0/18;
set_real_ip_from 2600:9000::/28;
# always put the following 2 lines in the bottom of ip list
real_ip_header X-Forwarded-For;
real_ip_recursive on;
3) make-nginx-real-ip-conf 란??
- AWS에서는 사용중인 ip를 json으로 공유해줍니다.
- 그중 CloudFront 대역 Ip v4, Ip v6만 파싱합니다.
- 내부 아이피 대역을 추가합니다. (지인의 말리퀘로 추가된 부분입니다.)
- nginx real ip에 필요한 CloudFront, ELB 대역만 정리하여 파일로 생성해주는 프로그램입니다.
* 참고로 https://ip-ranges.amazonaws.com/ip-ranges.json 가 변경되는 내용을 AWS SNS Topic으로 받을 수 있고, 해당 이벤트로 람다를 실행 시킬 수 있습니다.
* 참고링크
- http://serverfault.com/questions/331531/nginx-set-real-ip-from-aws-elb-load-balancer-address
'프로그래밍 > WebServer' 카테고리의 다른 글
[nginx] domain으로 referer block (0) | 2018.04.02 |
---|