From 83475e95987bb7fe403186d782d7db7a1cf6585a Mon Sep 17 00:00:00 2001 From: root Date: Sat, 30 Dec 2017 09:20:18 +0000 Subject: [PATCH 1/3] Ignore generated config files and certs. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore 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 From 6dae972e45fd55a7938f4798af452773fd882e83 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 30 Dec 2017 09:21:17 +0000 Subject: [PATCH 2/3] Make sure nginx restarts when the host does. --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) 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: From b83465375c0808ee61fa4d62553aa825c96d345d Mon Sep 17 00:00:00 2001 From: root Date: Sat, 30 Dec 2017 09:21:59 +0000 Subject: [PATCH 3/3] Use host port rather than container port so that redirects work when they differ. --- nginx/templates/nginx.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 }}