Created
July 5, 2023 20:47
-
-
Save kazem3d/f36683688815f1aea1f5db95556f2050 to your computer and use it in GitHub Desktop.
nginx and traefik with ssl/tls deployment with docker-compose [pro mode]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nginx and traefik with ssl/tls deployment with docker-compose [pro mode] | |
# Generate Treafik password | |
# echo $(htpasswd -nb user password) | sed -e s/\\$/\\$\\$/g | |
# http -> https redirect is not config and hendeled in dns resolver | |
version: '3.8' | |
networks: | |
traefik-network: # Define the custom network for Traefik and Nginx | |
services: | |
traefik: | |
image: traefik:v2.4 | |
command: | |
- "--log.level=INFO" | |
- "--log.filepath=/log-file.log" | |
- "--log.format=json" | |
- "--api.insecure=true" # Enable insecure mode for the Traefik UI | |
- "--providers.docker=true" | |
- "--providers.docker.exposedbydefault=false" | |
- "--entrypoints.web.address=:80" | |
- "--entrypoints.websecure.address=:443" # Enable HTTPS entrypoint on port 443 | |
- "--certificatesresolvers.myresolver.acme.tlschallenge=true" # Use TLS challenge | |
- "--certificatesresolvers.myresolver.acme.email=sample3d@gmail.com" # Set your email for Let's Encrypt notifications | |
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json" # Provide a path to store the Let's Encrypt certificates | |
ports: | |
- "80:80" # Expose port 80 for HTTP | |
- "443:443" # Expose port 443 for HTTPS | |
networks: | |
- traefik-network # Attach the Traefik service to the defined network | |
volumes: | |
- "/var/run/docker.sock:/var/run/docker.sock:ro" # Mount Docker socket | |
- "./letsencrypt:/letsencrypt" # Mount the Let's Encrypt certificate storage | |
labels: | |
- "traefik.enable=true" | |
- "traefik.http.routers.traefik.rule=Host(`my.sample47.ir`)" # Set domain rule for Traefik UI | |
- "traefik.http.routers.traefik.service=api@internal" | |
- "traefik.http.routers.traefik.tls.certresolver=myresolver" # Enable TLS for Traefik UI | |
- "traefik.http.middlewares.web-auth.basicauth.users=user:$$apr1$$QpkypDvQ$$FjJgBGyX/By8agkOCUvDo." #user/password auth | |
- "traefik.http.routers.traefik.middlewares=web-auth" | |
nginx: | |
image: nginx:latest | |
networks: | |
- traefik-network # Attach the Traefik service to the defined network | |
labels: | |
- "traefik.enable=true" | |
- "traefik.http.routers.nginx.rule=Host(`f.sample47.ir`)" | |
- "traefik.http.routers.nginx.entrypoints=websecure" # Use HTTPS entrypoint | |
- "traefik.http.routers.nginx.tls.certresolver=myresolver" # Enable TLS for Nginx | |
- "traefik.http.services.nginx.loadbalancer.server.port=80" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment