웹사이트를 호스팅하고 내 서버에서 마이크로서비스 프로젝트를 실행하고 싶습니다.
웹사이트는 Nginx 웹 서버로 실행됩니다. 웹사이트의 도메인은 Sampleapp.com과 유사하며 이 웹사이트는 freessl을 사용합니다.
마이크로서비스 프로젝트의 서비스 중 하나는 Nginx 웹 서버와 함께 도커 컨테이너의 서비스로 실행됩니다. 이 서비스는 api-dev.sampleapp.com과 같은 내 Sampleapp.com의 하위 도메인을 사용하며 해당 하위 도메인도 SSL과 함께 작동해야 합니다.
docker-compose를 사용하여 서비스를 배포하려고 하면 다음 오류가 발생합니다.
[경고] 1#1: 0.0.0.0:80에서 서버 이름 "api-dev.sample.com" 충돌, 무시됨
주요 관심사는 docker 내부에 SSL을 어떻게 설정할 수 있느냐는 것입니다. 443은 HTTPS의 기본 포트입니다.
내 마이크로서비스의 Nginx 구성 파일은 다음과 같습니다.
worker_processes auto;
events {
worker_connections 1024;
}
http {
server {
listen 80 default_server;
server_name "";
return 444;
}
server {
server_name game-dev.sampleapp.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://game_nodes;
proxy_redirect off;
}
}
server {
if ($host = game-dev.sampleapp.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name game-dev.sampleapp.com;
return 404;
}
upstream game_nodes {
# enable sticky session
# ip_hash;
server game-alpha:3000;
keepalive 8;
}
server {
server_name api-dev.sampleapp.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://main_nodes;
proxy_redirect off;
}
}
server {
# if ($host = api-dev.sampleapp.com) {
# return 301 https://$host$request_uri;
#}
listen 80;
listen [::]:80;
server_name api-dev.sampleapp.com;
return 404;
}
upstream main_nodes {
server main-alpha:8000;
server main-beta:8000;
keepalive 8;
}
}
웹사이트의 Nginx 구성 파일은 다음과 같습니다.
server {
listen 8080;
listen [::]:8080;
listen 8443 ssl http2;
listen [::]:8443 ssl http2;
server_name sampleapp.com www.sampleapp.com;
root /var/www/sampleapp.com;
index index.html;
ssl_certificate /etc/ssl/certs/sampleapp.com.pem;
ssl_certificate_key /etc/ssl/private/sampleapp.com.key;
ssl_client_certificate /etc/ssl/certs/origin-pull-ca.pem;
ssl_verify_client on;
client_max_body_size 100M;
autoindex off;
location / {
try_files $uri $uri/ =404;
}
}
저는 시스템 관리자가 아닌 개발자이기 때문에 이 작업을 수행하는 가장 좋은 방법을 찾는 데 어려움을 겪고 있습니다.
답변1
여기서 가능한 솔루션 중 하나는 Nginx로 3개의 Docker 컨테이너를 실행하는 것입니다.
- 80 및 443 포트를 수신하고 SSL을 오프로드하며 다른 두 컨테이너에 대한 역방향 프록시로 작동합니다.
- 웹사이트를 돌린다
- 마이크로서비스를 회전시킵니다