Merge pull request #72 from BenHall/default_host
Ability to set a default host for nginx
This commit is contained in:
commit
503072c03f
3 changed files with 19 additions and 3 deletions
|
@ -35,6 +35,13 @@ You can also use wildcards at the beginning and the end of host name, like `*.ba
|
||||||
|
|
||||||
If you would like to connect to your backend using HTTPS instead of HTTP, set `VIRTUAL_PROTO=https` on the backend container.
|
If you would like to connect to your backend using HTTPS instead of HTTP, set `VIRTUAL_PROTO=https` on the backend container.
|
||||||
|
|
||||||
|
### Default Host
|
||||||
|
|
||||||
|
To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example
|
||||||
|
|
||||||
|
$ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
|
||||||
|
|
||||||
|
|
||||||
### Separate Containers
|
### Separate Containers
|
||||||
|
|
||||||
nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://index.docker.io/u/jwilder/docker-gen/)
|
nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://index.docker.io/u/jwilder/docker-gen/)
|
||||||
|
|
11
nginx.tmpl
11
nginx.tmpl
|
@ -32,7 +32,7 @@ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
|
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80 default_server;
|
listen 80;
|
||||||
server_name _; # This is just an invalid value which will never trigger on a real hostname.
|
server_name _; # This is just an invalid value which will never trigger on a real hostname.
|
||||||
return 503;
|
return 503;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,16 @@ server {
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
{{ if $.Env.DEFAULT_HOST }}
|
||||||
|
{{ if eq $.Env.DEFAULT_HOST $host }}
|
||||||
|
listen 80 default_server;
|
||||||
server_name {{ $host }};
|
server_name {{ $host }};
|
||||||
|
{{ else }}
|
||||||
|
server_name {{ $host }};
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
server_name {{ $host }};
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
|
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
|
||||||
include {{ printf "/etc/nginx/vhost.d/%s" $host }};
|
include {{ printf "/etc/nginx/vhost.d/%s" $host }};
|
||||||
|
|
Reference in a new issue