diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8635f53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +nginx/certs +nginx/conf.d +nginx/vhost.d diff --git a/docker-compose.yml b/docker-compose.yml index e7d4dcb..16dd378 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ nginx: image: nginx:stable-alpine container_name: nginx + restart: unless-stopped volumes: - ./nginx/conf.d:/etc/nginx/conf.d - ./nginx/vhost.d:/etc/nginx/vhost.d @@ -13,6 +14,7 @@ nginx: nginx-gen: image: jwilder/docker-gen container_name: nginx-gen + restart: unless-stopped command: "-notify-sighup nginx -watch -only-exposed -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf" volumes_from: [nginx] volumes: @@ -21,6 +23,7 @@ nginx-gen: nginx-letsencrypt: image: jrcs/letsencrypt-nginx-proxy-companion container_name: nginx-letsencrypt + restart: unless-stopped links: [nginx-gen] volumes_from: [nginx] volumes: diff --git a/nginx/templates/nginx.tmpl b/nginx/templates/nginx.tmpl index 31ce729..6223f60 100644 --- a/nginx/templates/nginx.tmpl +++ b/nginx/templates/nginx.tmpl @@ -7,10 +7,10 @@ {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}} {{ else if .Address.IP }} # {{ .Container.Name }} - server {{ .Address.IP }}:{{ .Address.Port }}; + server {{ .Address.IP }}:{{ .Address.HostPort }}; {{ else }} # {{ .Container.Name }} - server {{ .Container.Name }}:{{ .Address.Port }}; + server {{ .Container.Name }}:{{ .Address.HostPort }}; {{ end }} {{ else }} # {{ .Container.Name }} @@ -85,7 +85,7 @@ upstream {{ $host }} { {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}} {{ else }} {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }} - {{ $address := where $container.Addresses "Port" $port | first }} + {{ $address := where $container.Addresses "HostPort" $port | first }} {{ template "upstream" (dict "Container" $container "Address" $address) }} {{ end }} {{ end }}