Elasticbeanstalk는 Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker를 사용하여 Apache, Nginx, Passenger, IIS와 같은 친숙한 서버에서 개발된 웹 애플리케이션 및 서비스를 간편하게 배포하고 조정할 수 있는 서비스이다.
Spring boot MVC를 war package하여 Elasticbeanstalk(tomcat)을 통해 배포하면 자동으로 WAS, WEB 서버가 프로비져닝되어 배포된다. 아주 간편하고 쉬운 배포지만 was control 뿐만아니라 web server을 어떻게 컨트롤 할지 의문이든다.
이 때를 위하여 Elasticbeanstalk는 .ebextensions를 사용하여 고급 환경 사용자 설정을 유도하고 있다. .ebextensions를 통해 배포시 apache설정, JVM 설정등을 포함하여 배포하면 배포시 자동적용된다.
이번 포스팅에서는 Tomcat was와 Nginx web server을 사용할때를 가정한다.
http 접속을 요청할 때 https로 auto redirect되도록 하는 configuration을 셋팅하는 예제를 아래에서 보여줄 것이다.
src/main/ebextensions의 내용을 war로 package시에 .ebextensions folder을 만들어 root directory에 저장하도록 한다.
org.springframework.boot spring-boot-maven-plugin maven-war-plugin 2.6 src/main/ebextensions .ebextensions true
| pom.xml + src/main | + ebextensions/nginx/conf.d/elasticbeanstalk/00_application.conf | + resources | + java/com.company/HelloworldApplication.java | + webapp/WEB-INF/jsp
location / { set $redirect 0; if ($http_x_forwarded_proto != "https") { set $redirect 1; } if ($http_user_agent ~* "ELB-HealthChecker") { set $redirect 0; } if ($redirect = 1) { return 301 https://$host$request_uri; } proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Connection $connection_upgrade; proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
End of Document
| aws ec2에 openJDK 1.8 설치하기 실습 예제 (0) | 2020.06.01 |
|---|---|
| EC2 SLA(서비스 계약 수준) 에 따른 uptime, downtime 시간 계산 (0) | 2020.05.28 |
| elasticbeanstalk + route53 으로 SSL(443) 접속 flask application 생성하는 가장 간단한 방법 (0) | 2020.05.15 |
| AWS MSK(Kafka) 실습 및 예제 코드(Java), 장단점, 가격 (3) | 2019.12.26 |
| AWS kinesis Data stream 실습 및 예제 코드(Java), 장단점, 가격 (0) | 2019.12.23 |
| AWS kinesis Firehose 실습 및 예제 코드(Java), 장단점, 가격 (5) | 2019.12.20 |