Refactor as UPSTREAM_REGEXES for more flexibility
This commit is contained in:
parent
9740ed4818
commit
e15ac5fc84
2 changed files with 13 additions and 11 deletions
|
@ -137,11 +137,13 @@ than a socket and expose that port.
|
|||
|
||||
If you use fastcgi, you can set `VIRTUAL_ROOT=xxx` for your root directory
|
||||
|
||||
### Sending only certain file extensions upstream
|
||||
### Sending only certain files upstream
|
||||
|
||||
You can set `UPSTREAM_EXTENSIONS=xxx` to only send certain extensions upstream.
|
||||
You can set `UPSTREAM_REGEXES=xxx` to only send certain requests upstream.
|
||||
The rest of the files will be served locally. If you want to send multiple
|
||||
extensions upstream, separate them like this: `UPSTREAM_EXTENSIONS=php|php5`
|
||||
regexes upstream, separate them like this: `UPSTREAM_REGEXES=/en|.*\.php|.*\.php5`
|
||||
|
||||
Above example will send example.com/en and all .php and .php5 files upstream.
|
||||
|
||||
When doing this, make sure the VIRTUAL_ROOT is also available to this container.
|
||||
The easiest way to do this is defining the VOLUME in your upstream container and
|
||||
|
|
16
nginx.tmpl
16
nginx.tmpl
|
@ -220,8 +220,8 @@ upstream {{ $upstream_name }} {
|
|||
{{/* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
|
||||
{{ $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
|
||||
|
||||
{{/* Which extensions to send upstream when using fastcgi, if not default, send everything upstream. Make sure the VIRTUAL_ROOT is available to this container when using this */}}
|
||||
{{ $vhost_upstream_extensions := trim (or (first (groupByKeys $containers "Env.UPSTREAM_EXTENSIONS")) "") }}
|
||||
{{/* Which regexes when matching to send upstream when using fastcgi. If not defined, send everything upstream. Make sure the VIRTUAL_ROOT is available to this container when using this */}}
|
||||
{{ $vhost_upstream_regexes := trim (or (first (groupByKeys $containers "Env.UPSTREAM_REGEXES")) "") }}
|
||||
|
||||
{{/* Which filename to use as index file */}}
|
||||
{{ $vhost_index := or (first (groupByKeys $containers "Env.INDEX")) "" }}
|
||||
|
@ -297,9 +297,9 @@ server {
|
|||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
{{ if $vhost_upstream_extensions }}
|
||||
{{ if $vhost_upstream_regexes }}
|
||||
root {{ trim $vhost_root }};
|
||||
location ~* \.({{ $vhost_upstream_extensions }})$ {
|
||||
location ~* "^({{ $vhost_upstream_regexes }})$" {
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
|
@ -325,7 +325,7 @@ server {
|
|||
}
|
||||
{{ end }}
|
||||
location / {
|
||||
{{ if not $vhost_upstream_extensions }}
|
||||
{{ if not $vhost_upstream_regexes }}
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
|
@ -378,9 +378,9 @@ server {
|
|||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
{{ if $vhost_upstream_extensions }}
|
||||
{{ if $vhost_upstream_regexes }}
|
||||
root {{ trim $vhost_root }};
|
||||
location ~* \.({{ $vhost_upstream_extensions }})$ {
|
||||
location ~* "^({{ $vhost_upstream_regexes }})$" {
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
|
@ -406,7 +406,7 @@ server {
|
|||
}
|
||||
{{ end }}
|
||||
location / {
|
||||
{{ if not $vhost_upstream_extensions }}
|
||||
{{ if not $vhost_upstream_regexes }}
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
|
|
Loading…
Reference in a new issue