วิธีติดตั้ง Let’s Encrypt


nginx-proxy
└── docker-compose.yml

docker-compose.yml

version: '3'

services:
  nginx-proxy:
    image: nginxproxy/nginx-proxy:alpine
    container_name: nginx-proxy
    restart: always
    ports:
      - "80:80"    # หรือพอร์ตที่ต้องการให้เข้าถึงจาก HAProxy
      - "443:443"
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy-network

  acme-companion:
    image: nginxproxy/acme-companion
    container_name: nginx-proxy-acme
    restart: always
    volumes_from:
      - nginx-proxy
    volumes:
      - certs:/etc/nginx/certs:rw
      - acme:/etc/acme.sh
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - [email protected]
    depends_on:
      - nginx-proxy

volumes:
  conf:
  vhost:
  html:
  certs:
  acme:

networks:
  proxy-network:
    external: true

nginx-proxy
web
├── docker-compose.yml
└── html
    └── index.html


docker-compose.yml

version: '3'

services:
  webapp:
    image: nginx:alpine  # หรือ image ของ web app ที่ใช้
    container_name: webapp
    restart: always
    expose:
      - "80"
    environment:
      - VIRTUAL_HOST=lab1.cpsudevops.com
      - LETSENCRYPT_HOST=lab1.cpsudevops.com
      - [email protected]
      - VIRTUAL_PORT=80
    volumes:
      - ./html:/usr/share/nginx/html
    networks:
      - proxy-network

networks:
  proxy-network:
    external: true

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>My Web App</title>
</head>
<body>
  <h1>Welcome to my website!</h1>
</body>
</html>
web