diff --git a/README.md b/README.md index 16ea017..c4d77a6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/nginx.tmpl b/nginx.tmpl index b0b38d7..09ce0ee 100644 --- a/nginx.tmpl +++ b/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 }};