-
[Network] Virtual HostInfra 2024. 8. 20. 09:42
Virtual Host(가상 호스트)는
하나의 물리적 서버에서 여러 개의 웹사이트를 호스팅할 수 있게 해주는 기술이다.
쉽게 말해, 하나의 컴퓨터로 여러 개의 웹사이트를 운영할 수 있게 해주는 방법이다.
그래서 여러 웹사이트를 위해 각각 서버를 구매하는 것보다 경제적이다.Virtual Host는 주로 두 가지 방식으로 작동한다
a) Name-based Virtual Hosting
b) IP-based Virtual Hosting
이 중 Name-based Virtual Hosting이 더 일반적으로 사용되고 있다.virtual host 를 적용하게 된 계기는 다음과 같다.
https://aws.amazon.com/ko/blogs/korea/new-aws-public-ipv4-address-charge-public-ip-insights/
공지 – AWS Public IPv4 주소 요금 변경 및 Public IP Insights 기능 출시 | Amazon Web Services
AWS에서 퍼블릭(Public) IPv4 주소에 대한 새로운 요금이 도입됩니다. 2024년 2월 1일부터 서비스 연결 여부에 관계없이 모든 퍼블릭 IPv4 주소에 대해 시간당 IP당 0.005 USD의 요금이 부과됩니다. 계정에
aws.amazon.com
aws 의 elb를 사용하고 있는데
ip4 주소를 가진 외부 로드밸런서를 사용하게 되면
public ip 를 사용하기에 비용이 더 증가하였다.
기존엔 서비스 하나 당 로드밸런서 하나를 설정했기에 많은 비용이 부과되었다.
적용 결과
적용 전 적용 후 비용을 200만원 정도 절약시킬 수 있었다.
시퀀스 다이어그램
우리는 dns 서버로 route 53을 사용하고 있다.
그래서 route53을 사용해서 내가 서비스할 ec2 인스턴스 하나로 라우팅한다.
그러면 example1.com 과 example2.com 으로 오는 요청을 받았을 때
그 앞에 있는 nginx 서버가 name based 규칙으로
내가 운영하고 있는 컨테이너로 요청을 전달한다.
아래는 내가 사용한 nginx 설정이다.
http { server { listen 80; server_name example1.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name example1.com; include /etc/nginx/mime.types; ssl_certificate /home/certs/example1.crt; ssl_certificate_key /home/certs/example1.key; root /webapp; index index.html; autoindex on; autoindex_exact_size off; autoindex_localtime on; error_page 404 /index.html; location / { try_files $uri $uri/ =404; } } server { listen 443 ssl; server_name example2.com; ssl_certificate /home/certs/example2.crt; ssl_certificate_key /home/certs/example2.key; location / { proxy_pass https://example2:8080; 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-Proto $scheme; } } server { listen 80; server_name example3.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name example3.com; ssl_certificate /home/certs/example3.crt; ssl_certificate_key /home/certs/example3.key; location / { proxy_pass http://127.0.0.1:9091; 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-Proto $scheme; } } }
proxy_pass 를 보면 localhost 로 설정할 수 있고
example2와 같이 컨테이너 이름으로 지정할 수 있다.
컨테이너 이름으로 지정하려면 당연히
도커 네트워크로 묶여있어야 하고
저 port 는 내부 port로 지정해야 한다.
'Infra' 카테고리의 다른 글
[프론트 배포] index.html 에 버저닝과 nginx 프록시로 브라우저 캐시문제 해결 (3) 2025.02.02 [Keycloak] 키클락 import error 해결 (4) 2024.10.21 [Network] CDN이 뭔지 알죠? (2) 2024.07.07