Skip to content

Commit fb59fbb

Browse files
authored
Merge pull request #11 from secondlife/signal/uwsgi
Add uWSGI support
2 parents dd71a17 + b32c087 commit fb59fbb

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUN apk add --no-cache \
2525
nginx \
2626
nginx-mod-http-headers-more
2727
COPY src /
28+
ENV PROXY_UWSGI=0
2829
ENV LISTEN_PORT=80
2930
ENV STATIC_LOCATIONS=
3031
EXPOSE 80
@@ -36,11 +37,16 @@ CMD ["nginx", "-g", "daemon off;"]
3637
# Run tests
3738
############
3839
FROM base AS test
39-
RUN apk add --no-cache curl go
40+
RUN apk add --no-cache curl go uwsgi-python3
41+
4042
COPY test /test
4143
WORKDIR /test
4244
RUN /test/test.sh
4345

46+
COPY test_uwsgi /test_uwsgi
47+
WORKDIR /test_uwsgi
48+
RUN /test_uwsgi/test.sh
49+
4450
############
4551
# Final
4652
############

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Pair nginx-proxy with your favorite upstream server (wsgi, uwsgi, asgi, et al.)
1313
| `SERVER_NAME` | Allowed server names (hostnames) | Yes | | |
1414
| `SILENT` | Silence entrypoint output | No | | |
1515
| `STATIC_LOCATIONS` | Static asset mappings | No | | |
16+
| `PROXY_UWSGI` | Whether to use native uwsgi support | No | 0 | 1 |
1617

1718
### Hosting Static Assets
1819

@@ -41,6 +42,13 @@ volumes:
4142
4243
The syntax of `STATIC_LOCATIONS` is `HOSTED_PATH1:LOCAL_PATH1,HOSTED_PATH2:LOCAL_PATH2`
4344

45+
## uWSGI
46+
47+
If you wish to use this service with uWSGI then define `PROXY_UWSGI=1` and set
48+
`PROXY_REVERSE_URL` to be the uwsgi `--socket` address of your app. (Do not
49+
use `http://`, ex. if your uwsgi server is hosting itself at `--socket :8000`
50+
then set `PROXY_REVERSE_URL=localhost:8000`.)
51+
4452
## Development
4553

4654
A test suite is baked into nginx-proxy's Dockerfile. You can run it by building

src/etc/nginx/templates/default.conf.template

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ server {
1818
add_header X-XSS-Protection "1; mode=block";
1919
add_header X-Content-Type-Options "nosniff";
2020

21+
{{ if (eq .Env.PROXY_UWSGI "1") }}
22+
location / {
23+
uwsgi_pass {{ .Env.PROXY_REVERSE_URL }};
24+
uwsgi_param HTTP_X_REQUEST_ID $request_id;
25+
uwsgi_param HTTP_HOST $host;
26+
include uwsgi_params;
27+
}
28+
{{ else }}
2129
location / {
2230
proxy_pass {{ .Env.PROXY_REVERSE_URL }};
2331
proxy_set_header X-Request-ID $request_id;
2432
proxy_set_header Host $host;
2533
}
34+
{{ end }}
2635

2736
{{ if .Env.STATIC_LOCATIONS }}
2837
{{ range (.Env.STATIC_LOCATIONS | strings.Split "," )}}

test/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ cleanup() {
3333
trap cleanup EXIT
3434

3535
TEST_URL="http://localhost:8080" go test
36+
37+
# Clean up, but leave this file if it fails
38+
rm /etc/nginx/conf.d/default.conf

test_uwsgi/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def application(env, start_response):
2+
start_response('200 OK', [('Content-Type','text/html')])
3+
return [b"Hello World"]

test_uwsgi/test.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function fail {
6+
echo "$@" >&2
7+
exit 1
8+
}
9+
10+
LISTEN_PORT="8080" \
11+
PROXY_REVERSE_URL="localhost:8081" \
12+
SERVER_NAME="localhost" \
13+
PROXY_UWSGI="1" \
14+
STATIC_LOCATIONS="/static/:/test/static/" \
15+
/docker-entrypoint.sh
16+
17+
# Start test server
18+
uwsgi --socket ":8081" --master --plugin python --wsgi-file app.py &
19+
app=$!
20+
21+
# Start reverse proxy
22+
nginx -g "daemon off;" &
23+
nginx=$!
24+
25+
sleep 1
26+
27+
cleanup() {
28+
kill $nginx
29+
kill $app
30+
}
31+
32+
trap cleanup EXIT
33+
34+
curl -fs http://localhost:8080/ || fail "Failed to get /"

0 commit comments

Comments
 (0)