AWS - 무중단 배포를 위한 NginX를 사용해보자

2022. 3. 1. 20:48CM/aws

반응형

1. ec2에  nginx install
먼저 sudo yum update -y로 업데이트 한 뒤
sudo yum install nginx  를 하면 아래와 같은 오류가 발생한다.

sudo amazon-linux-extras install nginx1으로 다시 해보자.

[ec2-user@acet-springboot-webservice ~]$ sudo amazon-linux-extras install nginx1
Installing nginx
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-kernel-5.10 amzn2extra-nginx1
17 metadata files removed
6 sqlite files removed
0 metadata files removed
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                                                                        | 3.7 kB  00:00:00
amzn2extra-docker                                                                                                                                                 | 3.0 kB  00:00:00
amzn2extra-kernel-5.10                                                                                                                                            | 3.0 kB  00:00:00
amzn2extra-nginx1                                                                                                                                                 | 3.0 kB  00:00:00
(1/9): amzn2-core/2/x86_64/group_gz                                                                                                                               | 2.5 kB  00:00:00
(2/9): amzn2-core/2/x86_64/updateinfo                                                                                                                             | 447 kB  00:00:00
(3/9): amzn2extra-kernel-5.10/2/x86_64/primary_db                                                                                                                 | 6.9 MB  00:00:00
(4/9): amzn2extra-docker/2/x86_64/updateinfo                                                                                                                      | 4.7 kB  00:00:00
(5/9): amzn2extra-docker/2/x86_64/primary_db                                                                                                                      |  83 kB  00:00:00
(6/9): amzn2extra-kernel-5.10/2/x86_64/updateinfo                                                                                                                 |  11 kB  00:00:00
(7/9): amzn2extra-nginx1/2/x86_64/updateinfo                                                                                                                      |   76 B  00:00:00
(8/9): amzn2extra-nginx1/2/x86_64/primary_db                                                                                                                      |  42 kB  00:00:00
(9/9): amzn2-core/2/x86_64/primary_db                                                                                                                             |  60 MB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.0-2.amzn2.0.4 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.20.0-2.amzn2.0.4 for package: 1:nginx-1.20.0-2.amzn2.0.4.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.0-2.amzn2.0.4.x86_64
--> Processing Dependency: libssl.so.1.1

인스톨이 완료되었다면 아래의 명령어로 nginx를 실행한다.
sudo service nginx start

2. EC2 80포트에 대한 보안그룹 설정
이제 EC2의 보안그룹에서 80포트에 대한 권한을 추가하자.

IPv4
IPV6

80포트로 붙어보면 아래와 같은 페이지가 열린다.

3. OAuth설정 구글, 네이버 수정
네이버랑 구글 OAuth설정에서 기존 포트설정되어있는것을 삭제하자.

4. NginX와 SpringBoot 연동
sudo vim /etc/nginx/nginx.conf 을 열어서 location부분을 추가해보자.

아래처럼 location을 추가!

위와같이 설정 후에 nginx를 재시작 합니다. 
sudo service nginx restart

그런 뒤 기존 8082포트를 붙여서 접속했던것을 포트를 빼고 접속을 해보면~~!! 잘떠야하는데 아래와 같은 오류가 날수 있다.

Something has triggered an error on your website. This is the default error page for nginx that is distributed with Amazon Linux 2. It is located /usr/share/nginx/html/50x.html

You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.

여러가지 방법을 시도했지만...역시나 안되면 재부팅이 답이다!
EC2를 재부팅 한번 해줬더니 잘됐다 ㅋㅋ

아마 인바운드 규칙을 수정 해주고 반영이 안된것 같다.
EC2가 재부팅 되면 springboot, nginx등 전부 재시작 해줘야 한다.

그리고나서 다시 접속해보면 아래와 같이 잘뜹니다!

 

- 끝 -

반응형