Skip to content

Build using docker compose

Brett Sutton edited this page Sep 4, 2020 · 6 revisions

The following example docker-compose.yaml shows Nginx-LE proxy in requests through to a web application server on port 8080.

It also assumes that you are running a local mail server on port 1025.

version: '3.3'

volumes:
  certificates:

services:
  # Nginx-LE configuration
  nginx-le:
    container_name: nginx-le
    image: noojee/nginx-le:latest
    restart: on-failure
    ports:
      - "80:80"
      - "443:443"
    network_mode: "host"
    environment:
      HOSTNAME: developer1
      DOMAIN: "acme.com.au"
      TLD: "com.au"
      EMAIL_ADDRESS: "me@acme.com.au"
      DOMAIN_WILDCARD: "false"
      AUTO_ACQUIRE: "true"
      PRODUCTION: "false" # changed to true to get a live certificate
      AUTH_PROVIDER: "cloudflare"
      AUTH_PROVIDER_TOKEN: "XXXXXXX"
      AUTH_PROVIDER_EMAIL_ADDRESS: "me@acme.com.au"
      EMAIL_ADDRESS: "me@acme.com.au"
      SMTP_SERVER: "localhost"
      SMTP_SERVER_PORT: "1025"
      DEBUG: "false"
      START_PAUSED: "false"
    volumes:
      - certificates:/etc/letsencrypt
      - /opt/nginx/include:/etc/nginx/include
    logging:
      driver: "journald"
  

On your host you need to create the following files in /opt/nginx/include

my_web_app_server.location

location / {
      	#try_files $uri $uri/ =404;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_max_temp_file_size 0;
        proxy_pass http://my_web_app_server/;
        proxy_read_timeout 300;
}

my_web_app_server.upstream

upstream my_web_app_server {
    server localhost:8080 fail_timeout=0;
}

Now you are ready to start you container:

docker compose up