Skip to content

Use upstream module with proxy_pass #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2024
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Pair nginx-proxy with your favorite upstream server (wsgi, uwsgi, asgi, et al.)
| Environment Variable | Description | Required | Default | Example |
|----------------------|-------------|----------|---------|---------|
| `LISTEN_PORT` | Server port | Yes | 80 | |
| `PROXY_REVERSE_URL` | Upstream server URL | Yes | | http://myapp:8080 |
| `UPSTREAM_SERVER` | Upstream server | Yes | | myapp:8080 fail_timeout=0, unix://mnt/server.sock |
| `PROXY_REVERSE_URL` | Upstream server URL (Deprecated, please use UPSTREAM_SERVER) | No | | http://myapp:8080 |
| `SERVER_NAME` | Allowed server names (hostnames) | Yes | | |
| `SILENT` | Silence entrypoint output | No | | |
| `STATIC_LOCATIONS` | Static asset mappings | No | | |
Expand Down Expand Up @@ -46,7 +47,7 @@ The syntax of `STATIC_LOCATIONS` is `HOSTED_PATH1:LOCAL_PATH1,HOSTED_PATH2:LOCAL
## 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
`UPSTREAM_SERVER` 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`.)

Expand Down
5 changes: 5 additions & 0 deletions src/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

# Transform legacy PROXY_REVERSE_URL to UPSTREAM_SERVER
if [[ -n $PROXY_REVERSE_URL ]]; then
export UPSTREAM_SERVER=${PROXY_REVERSE_URL#http://}
fi

run-parts --exit-on-error /docker-entrypoint.d

exec "$@"
9 changes: 7 additions & 2 deletions src/etc/nginx/templates/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ server {
}
{{ end }}

upstream app {
server {{ .Env.UPSTREAM_SERVER }};
}

server {
listen {{ .Env.LISTEN_PORT }};
server_name {{ .Env.SERVER_NAME }};
Expand All @@ -20,7 +24,7 @@ server {

{{ if (eq .Env.PROXY_UWSGI "1") }}
location / {
uwsgi_pass {{ .Env.PROXY_REVERSE_URL }};
uwsgi_pass app;
uwsgi_param HTTP_X_REQUEST_ID $request_id;
uwsgi_param HTTP_HOST $host;
include uwsgi_params;
Expand All @@ -29,9 +33,10 @@ server {
}
{{ else }}
location / {
proxy_pass {{ .Env.PROXY_REVERSE_URL }};
proxy_set_header X-Request-ID $request_id;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://app;
}
{{ end }}

Expand Down
2 changes: 1 addition & 1 deletion test_uwsgi/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function fail {

LISTEN_PORT="8080" \
KEEPALIVE_TIMEOUT="65" \
PROXY_REVERSE_URL="localhost:8081" \
UPSTREAM_SERVER="localhost:8081" \
SERVER_NAME="localhost" \
PROXY_UWSGI="1" \
STATIC_LOCATIONS="/static/:/test/static/" \
Expand Down