AWS ec2를 통해 Back 프로젝트를 배포 후,
잘 되던 API가 CORS 와 동시에 502 응답을 내놓고 있었다.
API 주소만 따로 접속하여 새로고침 한 결과
간헐적으로 200 응답도 보이고 있었다.
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(Collections.singletonList("*"));
configuration.setAllowedMethods(List.of("*"));
configuration.setAllowedHeaders(List.of("*"));
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
내가 OriginPatterns 부분에 접속 url을 실수한 경험이 있어 확인 해 봄.
원인이 아니였음.
로드밸런싱 부분의 타켓그룹 상태가 비정상을 확인.
트래픽이 적을 때는 상관 없으나, 트래픽이 많아질 때 중요한 부분.
그래서 이 비정상을 정상으로 돌려 봄.
AWS의 ALB를 사용하기 위해서는 타켓 그룹을 정상으로 유지하는 것이 중요하다!