Skip to content

Commit 503072c

Browse files
committed
Merge pull request nginx-proxy#72 from BenHall/default_host
Ability to set a default host for nginx
2 parents 11a8e51 + 30a53fb commit 503072c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Diff for: 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 128;/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

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ You can also use wildcards at the beginning and the end of host name, like `*.ba
3535

3636
If you would like to connect to your backend using HTTPS instead of HTTP, set `VIRTUAL_PROTO=https` on the backend container.
3737

38+
### Default Host
39+
40+
To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example
41+
42+
$ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
43+
44+
3845
### Separate Containers
3946

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

Diff for: 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
}
@@ -122,7 +122,16 @@ server {
122122
{{ else }}
123123

124124
server {
125-
server_name {{ $host }};
125+
{{ if $.Env.DEFAULT_HOST }}
126+
{{ if eq $.Env.DEFAULT_HOST $host }}
127+
listen 80 default_server;
128+
server_name {{ $host }};
129+
{{ else }}
130+
server_name {{ $host }};
131+
{{ end }}
132+
{{ else }}
133+
server_name {{ $host }};
134+
{{ end }}
126135

127136
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
128137
include {{ printf "/etc/nginx/vhost.d/%s" $host }};

0 commit comments

Comments
 (0)