Skip to content

Commit 30a53fb

Browse files
committed
Ability to set a default host for nginx
1 parent 6d646d9 commit 30a53fb

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update \
1313
RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
1414
&& sed -i 's/^http {/&\n server_names_hash_bucket_size 64;/g' /etc/nginx/nginx.conf
1515

16-
# Install Forego
16+
# Install Forego
1717
RUN wget -P /usr/local/bin https://godist.herokuapp.com/projects/ddollar/forego/releases/current/linux-amd64/forego \
1818
&& chmod u+x /usr/local/bin/forego
1919

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ If your container exposes multiple ports, nginx-proxy will default to the servic
2525

2626
If you need to support multipe virtual hosts for a container, you can separate each entry with commas. For example, `foo.bar.com,baz.bar.com,bar.com` and each host will be setup the same.
2727

28+
### Default Host
29+
30+
To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example
31+
32+
$ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
33+
34+
2835
### Separate Containers
2936

3037
nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://index.docker.io/u/jwilder/docker-gen/)

nginx.tmpl

+11-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3232
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
3333

3434
server {
35-
listen 80 default_server;
35+
listen 80;
3636
server_name _; # This is just an invalid value which will never trigger on a real hostname.
3737
return 503;
3838
}
@@ -115,7 +115,16 @@ server {
115115
{{ else }}
116116

117117
server {
118-
server_name {{ $host }};
118+
{{ if $.Env.DEFAULT_HOST }}
119+
{{ if eq $.Env.DEFAULT_HOST $host }}
120+
listen 80 default_server;
121+
server_name {{ $host }};
122+
{{ else }}
123+
server_name {{ $host }};
124+
{{ end }}
125+
{{ else }}
126+
server_name {{ $host }};
127+
{{ end }}
119128

120129
location / {
121130
proxy_pass http://{{ $host }};

0 commit comments

Comments
 (0)