diff --git a/pinhouse_docker/docker-compose.yml b/pinhouse_docker/docker-compose.yml index 2f381db..34bbbdb 100644 --- a/pinhouse_docker/docker-compose.yml +++ b/pinhouse_docker/docker-compose.yml @@ -35,6 +35,37 @@ services: networks: - backend-bridge + # Nginx Proxy + nginx: # nginx 서비스 정의 + image: nginx:latest # 사용할 Docker 이미지 + container_name: pinhouse-nginx + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./data/certbot/conf:/etc/letsencrypt + - ./data/certbot/www:/var/www/certbot + ports: + - 80:80 + - 443:443 + depends_on: + - spring + networks: + - backend-bridge + command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"''' + + certbot: + image: certbot/certbot + container_name: pinhouse-certbot + restart: unless-stopped + volumes: + - ./data/certbot/conf:/etc/letsencrypt + - ./data/certbot/www:/var/www/certbot + depends_on: + - nginx + networks: + - backend-bridge + entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" + + networks: backend-bridge: driver: bridge diff --git a/pinhouse_docker/nginx/nginx.conf b/pinhouse_docker/nginx/nginx.conf new file mode 100644 index 0000000..d59c8d0 --- /dev/null +++ b/pinhouse_docker/nginx/nginx.conf @@ -0,0 +1,39 @@ +events { + worker_connections 1024; +} + +http { + server { + listen 80; + server_name api.pinhouse.cloud; + + # Certbot 인증을 위한 경로 + location /.well-known/acme-challenge/ { + allow all; + root /var/www/certbot; + } + + # HTTP 요청은 HTTPS로 리디렉션 + location / { + return 301 https://$host$request_uri; + } + } + + server { + listen 443 ssl; + server_name api.pinhouse.cloud; + + # SSL 인증서 경로 + ssl_certificate /etc/letsencrypt/live/api.pinhouse.cloud-0001/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/api.pinhouse.cloud-0001/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; + + location / { + proxy_pass http://pinhouse-app:8080; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +}