1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2024-11-21 19:36:30 +00:00

Merge pull request #1353 from nanawel/feature/custom-external-ports-support

Add support for custom external HTTP/HTTPS ports
This commit is contained in:
Jason Wilder 2020-03-03 00:24:21 -05:00 committed by GitHub
commit b4709639b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,8 @@
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
{{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }}
{{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }}
{{ define "upstream" }}
{{ if .Address }}
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
@ -138,9 +141,9 @@ proxy_set_header Proxy "";
{{ $enable_ipv6 := eq (or ($.Env.ENABLE_IPV6) "") "true" }}
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 80;
listen {{ $external_http_port }};
{{ if $enable_ipv6 }}
listen [::]:80;
listen [::]:{{ $external_http_port }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
return 503;
@ -149,9 +152,9 @@ server {
{{ if (and (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 443 ssl http2;
listen {{ $external_https_port }} ssl http2;
{{ if $enable_ipv6 }}
listen [::]:443 ssl http2;
listen [::]:{{ $external_https_port }} ssl http2;
{{ end }}
access_log /var/log/nginx/access.log vhost;
return 503;
@ -241,9 +244,9 @@ upstream {{ $upstream_name }} {
{{ if eq $https_method "redirect" }}
server {
server_name {{ $host }};
listen 80 {{ $default_server }};
listen {{ $external_http_port }} {{ $default_server }};
{{ if $enable_ipv6 }}
listen [::]:80 {{ $default_server }};
listen [::]:{{ $external_http_port }} {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
@ -264,9 +267,9 @@ server {
server {
server_name {{ $host }};
listen 443 ssl http2 {{ $default_server }};
listen {{ $external_https_port }} ssl http2 {{ $default_server }};
{{ if $enable_ipv6 }}
listen [::]:443 ssl http2 {{ $default_server }};
listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
@ -336,7 +339,7 @@ server {
server {
server_name {{ $host }};
listen 80 {{ $default_server }};
listen {{ $external_http_port }} {{ $default_server }};
{{ if $enable_ipv6 }}
listen [::]:80 {{ $default_server }};
{{ end }}
@ -381,9 +384,9 @@ server {
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
server {
server_name {{ $host }};
listen 443 ssl http2 {{ $default_server }};
listen {{ $external_https_port }} ssl http2 {{ $default_server }};
{{ if $enable_ipv6 }}
listen [::]:443 ssl http2 {{ $default_server }};
listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
return 500;