Add support for adding options to the location block of a vhost
This commit is contained in:
parent
b131b00e19
commit
d9ee7ed704
2 changed files with 31 additions and 0 deletions
21
README.md
21
README.md
|
@ -198,3 +198,24 @@ If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=e
|
||||||
|
|
||||||
If you want most of your virtual hosts to use a default single configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default` file. This file
|
If you want most of your virtual hosts to use a default single configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default` file. This file
|
||||||
will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}` file associated with it.
|
will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}` file associated with it.
|
||||||
|
|
||||||
|
#### Per-VIRTUAL_HOST location configuration
|
||||||
|
|
||||||
|
To add settings to the "location" block on a per-`VIRTUAL_HOST` basis, add your configuration file under `/etc/nginx/vhost.d`
|
||||||
|
just like the previous section except with the suffix `_location`.
|
||||||
|
|
||||||
|
For example, if you have a virtual host named `app.example.com` and you have configured a proxy_cache `my-cache` in another custom file, you could tell it to use a proxy cache as follows:
|
||||||
|
|
||||||
|
$ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
|
||||||
|
$ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location
|
||||||
|
|
||||||
|
If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink:
|
||||||
|
|
||||||
|
$ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location
|
||||||
|
$ ln -s /path/to/vhost.d/www.example.com /path/to/vhost.d/example.com
|
||||||
|
|
||||||
|
#### Per-VIRTUAL_HOST location default configuration
|
||||||
|
|
||||||
|
If you want most of your virtual hosts to use a default single `location` block configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default_location` file. This file
|
||||||
|
will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}` file associated with it.
|
||||||
|
|
||||||
|
|
10
nginx.tmpl
10
nginx.tmpl
|
@ -135,6 +135,11 @@ server {
|
||||||
auth_basic "Restricted {{ $host }}";
|
auth_basic "Restricted {{ $host }}";
|
||||||
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
|
||||||
|
include {{ printf "/etc/nginx/vhost.d/%s_location"}}
|
||||||
|
{{ else if (exists /etc/vhost.d/defaults_location) }}
|
||||||
|
include /etc/nginx/vhost.d/defaults_location
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
@ -155,6 +160,11 @@ server {
|
||||||
auth_basic "Restricted {{ $host }}";
|
auth_basic "Restricted {{ $host }}";
|
||||||
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
|
||||||
|
include {{ printf "/etc/nginx/vhost.d/%s_location"}}
|
||||||
|
{{ else if (exists /etc/vhost.d/defaults_location) }}
|
||||||
|
include /etc/nginx/vhost.d/defaults_location
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue