Adding the ability to serve static files with nginx-proxy
This is done by intruducing a new VIRTUAL_PROTO=static. The VIRTUAL_ROOT variable points to the static root which should be mounted into the container as volume. Often the container of the static website does not need to run, so I introduced a new environment variable INCLUDE_STOPPED_CONTAINERS that adds the -include-stopped flag to docker-gen
This commit is contained in:
parent
226bfe158f
commit
e2e6964944
4 changed files with 18 additions and 1 deletions
2
Procfile
2
Procfile
|
@ -1,2 +1,2 @@
|
|||
dockergen: docker-gen -watch -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf
|
||||
dockergen: docker-gen -watch${INCLUDE_STOPPED} -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf
|
||||
nginx: nginx
|
||||
|
|
|
@ -136,6 +136,15 @@ than a socket and expose that port.
|
|||
|
||||
If you use fastcgi,you can set `VIRTUAL_ROOT=xxx` for your root directory
|
||||
|
||||
### Static File Backends
|
||||
|
||||
If you want your container to only serve static content, set `VIRTUAL_PROTO=static` on the container.
|
||||
You can then set `VIRTUAL_ROOT=xxx` to your static files' root directory. If your static files live in a stopped
|
||||
container, be sure to set the `INCLUDE_STOPPED_CONTAINERS=true` environment variable on the nginx-proxy container as
|
||||
stopped containers will otherwise be ignored.
|
||||
|
||||
You can create a minimal docker container with your static website files in a volume. The volume can then be mounted
|
||||
into the nginx-proxy container and be served with this "backend".
|
||||
|
||||
### Default Host
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ if [[ $DOCKER_HOST = unix://* ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ "${INCLUDE_STOPPED_CONTAINERS}" == "true" ]; then
|
||||
export INCLUDE_STOPPED=" -include-stopped"
|
||||
fi
|
||||
|
||||
# Generate dhparam file if required
|
||||
# Note: if $DHPARAM_BITS is not defined, generate-dhparam.sh will use 2048 as a default
|
||||
/app/generate-dhparam.sh $DHPARAM_BITS
|
||||
|
|
|
@ -277,6 +277,8 @@ server {
|
|||
root {{ trim $vhost_root }};
|
||||
include fastcgi.conf;
|
||||
fastcgi_pass {{ trim $upstream_name }};
|
||||
{{ else if eq $proto "static" }}
|
||||
root {{ trim $vhost_root }};
|
||||
{{ else }}
|
||||
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
{{ end }}
|
||||
|
@ -324,6 +326,8 @@ server {
|
|||
root {{ trim $vhost_root }};
|
||||
include fastcgi.conf;
|
||||
fastcgi_pass {{ trim $upstream_name }};
|
||||
{{ else if eq $proto "static" }}
|
||||
root {{ trim $vhost_root }};
|
||||
{{ else }}
|
||||
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue