nginx에서 Internal-LB 주소를 Reverse proxy로 지정할 때 다음과 같은 에러가 발생하였다.
AWS ELB는 복수의 IP가 할당된다. ELB는 EC2 인스턴스의 집합체이기에 동적으로 ip들이 늘어나거나 줄어든다. 즉 nginx 설정 파일을 읽는 시점에 도메인의 ip를 resolve하는데 이 사이에 ELB의 동적 IP 변경이 발생 시 발생한다.
proxy_pass http://[NLB DNS 경로]:8080;
이를 변수로 할당한다
ec2 - class의 dns는 172.16.0.23
ec2- vpc의 dns는 vpc 네트워크 대역대에서 range+2이다
즉 172.31.0.0/16이라면 172.31.0.2 이다
- vi /etc/nginx/nginx.conf
set $target "internal-was-493631525.ap-northeast-2.elb.amazonaws.com";
location / {
proxy_pass http://$target:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
결과적으로 해결이 되었는가? 라는 질문에 내 대답은… 알고보니 이전에 만들어두었던 ELB 주소를 사용하였기에 발생한 문제였다. 그래서 ELB 주소를 지금 사용하고 있는 ELB 주소를 넣어서 해결하였다.
출처:
Amazon EC2 instance IP addressing
'문제해결' 카테고리의 다른 글
pm2 start시 pem 권한 문제 (0) | 2024.06.08 |
---|---|
pm2 had too many unstable restarts(16). stopped. “errored” (0) | 2024.06.08 |
[SpringBoot] JSON과 image 동시에 값 보내기 (0) | 2023.08.18 |
[SpringBoot] JPA 테이블 또는 필드를 찾지 못할 때 (0) | 2023.08.18 |
[AWS] EC2 Out Of Memory (0) | 2023.08.17 |