728x90
원래는 EC2 Host OS에 NGINX를 직접 설치해서 사용했으나,
nginx 설정이나 인증서 등을 관리할 때 다 직접하면 불편할 것 같아서 nginx도 컨테이너로 만들어 버렸다.
더불어, Jenkins도 이미지를 이용해서 컨테이너로 만들었다. Jenkins는 방식이 거의 유사해서 따로 포스팅은 안 해도 될 것 같다:)
먼저 로컬에 nginx 디렉토리를 하나 생성하고
Dockerfile을 다음과 같이 만들면 NGINX를 바로 사용할 수 있다.
FROM nginx
nginx.conf도 수정해 주어야 하기 때문에, nginx 디렉토리에 nginx.conf 파일을 만들고 다음과 같이 작성했다.
server {
listen 80;
server_name 도메인;
server_tokens off;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name 도메인;
location / {
proxy_pass http://172.17.0.1:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
ssl_certificate /etc/nginx/ssl/nginx_ssl.crt;
ssl_certificate_key /etc/nginx/ssl/키;
ssl_session_timeout 3y;
ssl_prefer_server_ciphers on;
}
도커 파일은 다음과 같이 수정했다.
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
RUN mkdir /etc/nginx/ssl
# ssl 인증서 복사
COPY nginx_ssl.crt /etc/nginx/ssl
COPY 키 /etc/nginx/ssl
코모도 인증서를 crt로 만들어서(https://www.comodossl.co.kr/certificate/ssl-installation-guides/Nginx.aspx) 함께 이미지로 만든다
728x90
'Server > DevOps' 카테고리의 다른 글
Jenkins Pipeline 사용법 (0) | 2022.08.25 |
---|---|
CI/CD (Github Actions와 Jenkins 비교) (0) | 2022.08.25 |
[AWS] Jenkins CI/CD 구축하기_(2) (0) | 2022.08.25 |
[AWS] Jenkins CI/CD 구축하기_(1) (0) | 2022.08.25 |
[AWS] EC2 Docker 설치 및 컨테이너 실행 (+NGINX) (0) | 2022.08.25 |