Skip to content

Commit

Permalink
Refactor as UPSTREAM_REGEXES for more flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Dec 31, 2019
1 parent 9740ed4 commit e15ac5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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")) "" }}
Expand Down Expand Up @@ -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 }};
Expand All @@ -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 }};
Expand Down Expand Up @@ -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 }};
Expand All @@ -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 }};
Expand Down

0 comments on commit e15ac5f

Please sign in to comment.