🌍 Networking

SSL Termination

SSL Termination

SSL decryption at the load balancer. Reduces backend load.

📖 Detailed Explanation

SSL Termination (also called TLS Termination) is an architecture pattern in which a load balancer or reverse proxy decrypts encrypted HTTPS connections and communicates with backend servers over plaintext HTTP. Only the client → load balancer segment is encrypted, while the load balancer → backend server segment is not encrypted.

SSL/TLS encryption and decryption are CPU-intensive tasks. In particular, during the TLS handshake, an RSA 2048-bit key exchange consumes several milliseconds of CPU time per connection. When SSL termination is applied, this load is concentrated on the dedicated load balancer, so backend servers can focus solely on business logic. AWS ALB can handle tens of thousands of TLS connections per second.

Certificate management is also greatly simplified. Without SSL termination, certificates must be installed and renewed on every backend server, but with SSL termination, certificates only need to be managed in one place, the load balancer. Combined with services such as Let's Encrypt automatic renewal or AWS Certificate Manager, the risk of outages caused by certificate expiration can be significantly reduced.

From a security perspective, SSL termination involves a trade-off. Because the internal network segment is exposed as plaintext, it should be used only within a trusted private network (VPC). In regulated environments such as finance and healthcare, end-to-end encryption may be required, so SSL Passthrough or Re-encryption may need to be considered.

💻 Code Example

# Nginx SSL 종료 설정
# /etc/nginx/conf.d/ssl-termination.conf

upstream backend_servers {
    server 10.0.1.10:8080;  # 백엔드는 HTTP (8080)
    server 10.0.1.11:8080;
    server 10.0.1.12:8080;
    keepalive 32;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    # SSL 인증서 (Let's Encrypt 또는 상용 인증서)
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    # 최신 TLS 보안 설정
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
    ssl_prefer_server_ciphers off;

    # OCSP Stapling (인증서 유효성 검증 가속화)
    ssl_stapling on;
    ssl_stapling_verify on;

    # 백엔드로 HTTP 평문 전달
    location / {
        proxy_pass http://backend_servers;
        proxy_http_version 1.1;
        proxy_set_header Connection "";

        # 원본 클라이언트 정보 전달
        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;  # https
    }
}

# HTTP → HTTPS 리다이렉트
server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}
# HAProxy SSL 종료 설정
# /etc/haproxy/haproxy.cfg

global
    ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256
    ssl-default-bind-options ssl-min-ver TLSv1.2
    tune.ssl.default-dh-param 2048
    maxconn 50000

defaults
    mode http
    timeout connect 5s
    timeout client 30s
    timeout server 30s
    option httplog

# HTTPS 프론트엔드 (SSL 종료 지점)
frontend https_front
    bind *:443 ssl crt /etc/haproxy/certs/example.com.pem

    # HSTS 헤더 추가
    http-response set-header Strict-Transport-Security "max-age=31536000"

    # 원본 정보 헤더 추가
    http-request set-header X-Forwarded-Proto https
    http-request set-header X-Real-IP %[src]

    default_backend http_back

# HTTP 리다이렉트
frontend http_front
    bind *:80
    redirect scheme https code 301

# 백엔드 (평문 HTTP)
backend http_back
    balance roundrobin
    option httpchk GET /health

    server web1 10.0.1.10:8080 check
    server web2 10.0.1.11:8080 check
    server web3 10.0.1.12:8080 check
# AWS ALB SSL 종료 - Terraform 설정
# main.tf

# ACM 인증서 (자동 갱신)
resource "aws_acm_certificate" "main" {
  domain_name       = "example.com"
  validation_method = "DNS"

  lifecycle {
    create_before_destroy = true
  }
}

# Application Load Balancer
resource "aws_lb" "main" {
  name               = "main-alb"
  internal           = false
  load_balancer_type = "application"
  security_groups    = [aws_security_group.alb.id]
  subnets            = var.public_subnets
}

# HTTPS 리스너 (SSL 종료)
resource "aws_lb_listener" "https" {
  load_balancer_arn = aws_lb.main.arn
  port              = 443
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-TLS13-1-2-2021-06"
  certificate_arn   = aws_acm_certificate.main.arn

  default_action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.main.arn
  }
}

# HTTP → HTTPS 리다이렉트
resource "aws_lb_listener" "http" {
  load_balancer_arn = aws_lb.main.arn
  port              = 80
  protocol          = "HTTP"

  default_action {
    type = "redirect"
    redirect {
      port        = "443"
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }
  }
}

# 타겟 그룹 (백엔드는 HTTP)
resource "aws_lb_target_group" "main" {
  name     = "main-tg"
  port     = 8080      # 백엔드는 평문 HTTP
  protocol = "HTTP"    # SSL 없음
  vpc_id   = var.vpc_id

  health_check {
    path                = "/health"
    healthy_threshold   = 2
    unhealthy_threshold = 3
  }
}

🗣️ Say It Like This in Practice

💬 In an architecture design meeting
"If we handle SSL termination at the ALB, we can reduce the CPU load on the backend EC2 instances by 20-30%. Certificate management is also automatically renewed in ACM, so the operational burden is greatly reduced. However, communication between the ALB and the backend is plaintext, so we need to make sure the security group settings ensure that traffic flows only inside the VPC."
💬 In a Security Review Meeting
"If regulatory requirements call for end-to-end encryption, you need to use SSL Passthrough or Re-encryption. Passthrough is a method where the load balancer passes traffic through as is without touching the encryption, and Re-encryption is a method where the load balancer decrypts the traffic and then encrypts it again before sending it to the backend. Please choose by weighing the trade-off between performance and security."
💬 In an Incident Response Situation
"Check the X-Forwarded-Proto header on the backend. After SSL termination, the proxy needs to set this header so that the app can tell whether a request is HTTPS. Without this header, the app may treat the request as HTTP, which can cause an infinite redirect loop."

⚠️ Common Mistakes & Cautions

❌
Ignoring Internal Network Security

Because the backend segment is plaintext after SSL termination, communication must take place only within a VPC/private network. Plaintext communication over a public network carries a risk of man-in-the-middle (MITM) attacks.

❌
X-Forwarded Headers Not Set

If the X-Forwarded-Proto and X-Forwarded-For headers are not set after SSL termination, the backend cannot know the original client IP and protocol. Logging, security policies, and HTTPS redirect logic will malfunction.

❌
No Certificate Expiration Monitoring

If the certificate at the SSL termination point expires, the entire service goes down. Use ACM automatic renewal, or set up an alert 30 days before expiration along with certbot automation.

✅
Correct SSL Termination Configuration

Allow only TLS 1.2 or higher, set the HSTS header, and use strong cipher suites. On AWS, apply a policy of ELBSecurityPolicy-TLS13-1-2-2021-06 or higher, and monitor SSL handshake errors with CloudWatch.

🔗 Related Terms

📚 Learn More