Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RUN apk add --no-cache \
nginx \
nginx-mod-http-headers-more
COPY src /
ENV PROXY_UWSGI=0
ENV LISTEN_PORT=80
ENV STATIC_LOCATIONS=
EXPOSE 80
Expand All @@ -36,11 +37,16 @@ CMD ["nginx", "-g", "daemon off;"]
# Run tests
############
FROM base AS test
RUN apk add --no-cache curl go
RUN apk add --no-cache curl go uwsgi-python3

COPY test /test
WORKDIR /test
RUN /test/test.sh

COPY test_uwsgi /test_uwsgi
WORKDIR /test_uwsgi
RUN /test_uwsgi/test.sh

############
# Final
############
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Pair nginx-proxy with your favorite upstream server (wsgi, uwsgi, asgi, et al.)
| `SERVER_NAME` | Allowed server names (hostnames) | Yes | | |
| `SILENT` | Silence entrypoint output | No | | |
| `STATIC_LOCATIONS` | Static asset mappings | No | | |
| `PROXY_UWSGI` | Whether to use native uwsgi support | No | 0 | 1 |

### Hosting Static Assets

Expand Down Expand Up @@ -41,6 +42,13 @@ volumes:

The syntax of `STATIC_LOCATIONS` is `HOSTED_PATH1:LOCAL_PATH1,HOSTED_PATH2:LOCAL_PATH2`

## uWSGI

If you wish to use this service with uWSGI then define `PROXY_UWSGI=1` and set
`PROXY_REVERSE_URL` to be the uwsgi `--socket` address of your app. (Do not
use `http://`, ex. if your uwsgi server is hosting itself at `--socket :8000`
then set `PROXY_REVERSE_URL=localhost:8000`.)

## Development

A test suite is baked into nginx-proxy's Dockerfile. You can run it by building
Expand Down
9 changes: 9 additions & 0 deletions src/etc/nginx/templates/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ server {
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

{{ if (eq .Env.PROXY_UWSGI "1") }}
location / {
uwsgi_pass {{ .Env.PROXY_REVERSE_URL }};
uwsgi_param HTTP_X_REQUEST_ID $request_id;
uwsgi_param HTTP_HOST $host;
include uwsgi_params;
}
{{ else }}
location / {
proxy_pass {{ .Env.PROXY_REVERSE_URL }};
proxy_set_header X-Request-ID $request_id;
proxy_set_header Host $host;
}
{{ end }}

{{ if .Env.STATIC_LOCATIONS }}
{{ range (.Env.STATIC_LOCATIONS | strings.Split "," )}}
Expand Down
3 changes: 3 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ cleanup() {
trap cleanup EXIT

TEST_URL="http://localhost:8080" go test

# Clean up, but leave this file if it fails
rm /etc/nginx/conf.d/default.conf
3 changes: 3 additions & 0 deletions test_uwsgi/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
34 changes: 34 additions & 0 deletions test_uwsgi/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -e

function fail {
echo "$@" >&2
exit 1
}

LISTEN_PORT="8080" \
PROXY_REVERSE_URL="localhost:8081" \
SERVER_NAME="localhost" \
PROXY_UWSGI="1" \
STATIC_LOCATIONS="/static/:/test/static/" \
/docker-entrypoint.sh

# Start test server
uwsgi --socket ":8081" --master --plugin python --wsgi-file app.py &
app=$!

# Start reverse proxy
nginx -g "daemon off;" &
nginx=$!

sleep 1

cleanup() {
kill $nginx
kill $app
}

trap cleanup EXIT

curl -fs http://localhost:8080/ || fail "Failed to get /"