1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-07-03 07:15:46 +00:00

6 Commits

Author SHA1 Message Date
7470514e7b Merge pull request #1 from harvdogg/master
Allow complete override of location blocks
2020-04-13 19:45:23 +02:00
3cbc5417b7 Merge pull request #1113 from basro/master
Set DISABLE_ACCESS_LOGS env var to disable access logs
2020-03-25 14:27:02 -06:00
8219788df6 Merge branch 'master' into master 2020-03-25 14:26:30 -06:00
593c3c29b0 Adjusted formatting on README 2018-10-17 19:22:14 -07:00
c984ed2b18 Added support for completely overriding the location blocks for proxied containers. 2018-10-17 19:21:02 -07:00
f68383add9 Set DISABLE_ACCESS_LOGS to disable access logs 2018-03-27 21:18:45 -03:00
2 changed files with 36 additions and 8 deletions

View File

@ -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.

View File

@ -138,6 +138,8 @@ proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
proxy_set_header Proxy "";
{{ end }}
{{ $access_log := (or (and (not $.Env.DISABLE_ACCESS_LOGS) "access_log /var/log/nginx/access.log vhost;") "") }}
{{ $enable_ipv6 := eq (or ($.Env.ENABLE_IPV6) "") "true" }}
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
@ -145,7 +147,7 @@ server {
{{ if $enable_ipv6 }}
listen [::]:{{ $external_http_port }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
{{ $access_log }}
return 503;
}
@ -156,7 +158,7 @@ server {
{{ if $enable_ipv6 }}
listen [::]:{{ $external_https_port }} ssl http2;
{{ end }}
access_log /var/log/nginx/access.log vhost;
{{ $access_log }}
return 503;
ssl_session_cache shared:SSL:50m;
@ -248,12 +250,11 @@ server {
{{ if $enable_ipv6 }}
listen [::]:{{ $external_http_port }} {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
{{ $access_log }}
# Do not HTTPS redirect Let'sEncrypt ACME challenge
location ^~ /.well-known/acme-challenge/ {
location /.well-known/acme-challenge/ {
auth_basic off;
auth_request off;
allow all;
root /usr/share/nginx/html;
try_files $uri =404;
@ -272,7 +273,7 @@ server {
{{ if $enable_ipv6 }}
listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
{{ $access_log }}
{{ if eq $network_tag "internal" }}
# Only allow traffic from internal clients
@ -308,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;
@ -332,6 +336,7 @@ server {
include /etc/nginx/vhost.d/default_location;
{{ end }}
}
{{ end }}
}
{{ end }}
@ -344,7 +349,7 @@ server {
{{ if $enable_ipv6 }}
listen [::]:80 {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
{{ $access_log }}
{{ if eq $network_tag "internal" }}
# Only allow traffic from internal clients
@ -357,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;
@ -380,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")) }}
@ -389,7 +398,7 @@ server {
{{ if $enable_ipv6 }}
listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }};
{{ end }}
access_log /var/log/nginx/access.log vhost;
{{ $access_log }}
return 500;
ssl_certificate /etc/nginx/certs/default.crt;