mirror of
https://github.com/thib8956/nginx-proxy
synced 2024-11-21 11:26:31 +00:00
Merge pull request #1 from harvdogg/master
Allow complete override of location blocks
This commit is contained in:
commit
7470514e7b
19
README.md
19
README.md
@ -403,6 +403,25 @@ 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 `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}_location` file associated with it.
|
||||
|
||||
#### Pre-VIRTUAL_HOST custom location blocks
|
||||
|
||||
In some circumstances you may want to override nginx's default `/` location block behavior. Typically, this block acts as a catch-all in order to forward requests not already matched by a specific `location` block directly onto your container as-is.
|
||||
|
||||
To provide your own location blocks and bypass the automatic generation of them, simply add your location blocks to a configuration file file under `/etc/nginx/vhost.d` like in the other Per-VIRTUAL_HOST sections except with the suffix `_locations`. Notice the 's' to make the filename plural.
|
||||
The contents of this file will replace all auto-generated location blocks. Additionally, this file will take priority over the previously described location configuration.
|
||||
|
||||
When using location overrides, you are responsible for handling any requests that should be forwarded to your container. Passing a request to your container is done using the `proxy_pass` instruction within your defined location blocks. `proxy_pass` expects a qualified hostname in order
|
||||
to forward a request. By default, nginx-proxy aliases containers to the defined `VIRTUAL_HOST` name. So if you launch your container with a `VIRTUAL_HOST` value of `app.example.com`, then forwarding a request to your container would look something like this:
|
||||
|
||||
```
|
||||
location / {
|
||||
proxy_pass http://app.example.com;
|
||||
}
|
||||
```
|
||||
|
||||
If you are using an SSL-enabled container, you would use `https://` in place of `http://`. You could include any number of other location blocks for nginx to consider and even forward requests to external hosts when they match certain conditions. You can also use any other rules and instructions
|
||||
available to nginx location blocks.
|
||||
|
||||
### Contributing
|
||||
|
||||
Before submitting pull requests or issues, please check github to make sure an existing issue or pull request is not already open.
|
||||
|
@ -309,6 +309,9 @@ server {
|
||||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
{{ if (exists (printf "/etc/nginx/vhost.d/%s_locations" $host)) }}
|
||||
include {{ printf "/etc/nginx/vhost.d/%s_locations" $host}};
|
||||
{{ else }}
|
||||
location / {
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
@ -333,6 +336,7 @@ server {
|
||||
include /etc/nginx/vhost.d/default_location;
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
@ -358,6 +362,9 @@ server {
|
||||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
{{ if (exists (printf "/etc/nginx/vhost.d/%s_locations" $host)) }}
|
||||
include {{ printf "/etc/nginx/vhost.d/%s_locations" $host}};
|
||||
{{ else }}
|
||||
location / {
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
@ -381,6 +388,7 @@ server {
|
||||
include /etc/nginx/vhost.d/default_location;
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
|
||||
|
Loading…
Reference in New Issue
Block a user