Skip to content

Commit 53110e9

Browse files
committed
Use upstream module with proxy_pass
Place servers in an upstream module block to allow greater flexibility in definition. `fail_timeout`, etc. can now be specified, and unix sockets and tcp servers both used.
1 parent 40ccac4 commit 53110e9

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Pair nginx-proxy with your favorite upstream server (wsgi, uwsgi, asgi, et al.)
99
| Environment Variable | Description | Required | Default | Example |
1010
|----------------------|-------------|----------|---------|---------|
1111
| `LISTEN_PORT` | Server port | Yes | 80 | |
12-
| `PROXY_REVERSE_URL` | Upstream server URL | Yes | | http://myapp:8080 |
12+
| `UPSTREAM_SERVER` | Upstream server | Yes | | myapp:8080 fail_timeout=0, unix://mnt/server.sock |
13+
| `PROXY_REVERSE_URL` | Upstream server URL (Deprecated, please use UPSTREAM_SERVER) | No | | http://myapp:8080 |
1314
| `SERVER_NAME` | Allowed server names (hostnames) | Yes | | |
1415
| `SILENT` | Silence entrypoint output | No | | |
1516
| `STATIC_LOCATIONS` | Static asset mappings | No | | |
@@ -46,7 +47,7 @@ The syntax of `STATIC_LOCATIONS` is `HOSTED_PATH1:LOCAL_PATH1,HOSTED_PATH2:LOCAL
4647
## uWSGI
4748

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

src/docker-entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -e
44

5+
# Transform legacy PROXY_REVERSE_URL to UPSTREAM_SERVER
6+
if [[ -n $PROXY_REVERSE_URL ]]; then
7+
export UPSTREAM_SERVER=${PROXY_REVERSE_URL#http://}
8+
fi
9+
510
run-parts --exit-on-error /docker-entrypoint.d
611

712
exec "$@"

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ server {
88
}
99
{{ end }}
1010

11+
upstream app {
12+
server {{ .Env.UPSTREAM_SERVER }};
13+
}
14+
1115
server {
1216
listen {{ .Env.LISTEN_PORT }};
1317
server_name {{ .Env.SERVER_NAME }};
@@ -20,7 +24,7 @@ server {
2024

2125
{{ if (eq .Env.PROXY_UWSGI "1") }}
2226
location / {
23-
uwsgi_pass {{ .Env.PROXY_REVERSE_URL }};
27+
uwsgi_pass app;
2428
uwsgi_param HTTP_X_REQUEST_ID $request_id;
2529
uwsgi_param HTTP_HOST $host;
2630
include uwsgi_params;
@@ -29,9 +33,10 @@ server {
2933
}
3034
{{ else }}
3135
location / {
32-
proxy_pass {{ .Env.PROXY_REVERSE_URL }};
3336
proxy_set_header X-Request-ID $request_id;
3437
proxy_set_header Host $host;
38+
proxy_redirect off;
39+
proxy_pass http://app;
3540
}
3641
{{ end }}
3742

test_uwsgi/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function fail {
99

1010
LISTEN_PORT="8080" \
1111
KEEPALIVE_TIMEOUT="65" \
12-
PROXY_REVERSE_URL="localhost:8081" \
12+
UPSTREAM_SERVER="localhost:8081" \
1313
SERVER_NAME="localhost" \
1414
PROXY_UWSGI="1" \
1515
STATIC_LOCATIONS="/static/:/test/static/" \

0 commit comments

Comments
 (0)