Skip to content

Add support for STATUS_LISTEN_PORT env var #29

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ COPY src /
ENV KEEPALIVE_TIMEOUT=65
ENV PROXY_UWSGI=0
ENV LISTEN_PORT=80
ENV STATUS_LISTEN_PORT=8091
Copy link
Preview

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default port (8091) is defined in multiple places (Dockerfile, template, docs); consider centralizing this default or referencing a single source to avoid drift.

Suggested change
ENV STATUS_LISTEN_PORT=8091
ARG DEFAULT_STATUS_LISTEN_PORT=8091
ENV STATUS_LISTEN_PORT=$DEFAULT_STATUS_LISTEN_PORT

Copilot uses AI. Check for mistakes.

ENV HEALTHCHECK_PATH="/lb-status/"
ENV STATIC_LOCATIONS=
ENV NO_ACCESS_LOGS=0
Expand Down Expand Up @@ -41,4 +42,4 @@ RUN /test_uwsgi/test.sh
FROM base
LABEL "com.datadoghq.ad.check_names"='["nginx"]'
LABEL "com.datadoghq.ad.init_configs"='[{}]'
LABEL "com.datadoghq.ad.instances"='[{"nginx_status_url": "http://localhost:8091/nginx_status/"}]'
LABEL "com.datadoghq.ad.instances"='[{"nginx_status_url": "http://%%host%%:%%env_STATUS_LISTEN_PORT%%/nginx_status/"}]'
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 | |
| `STATUS_LISTEN_PORT` | nginx status port | No | 8091 | |
| `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 | | |
Expand Down Expand Up @@ -65,8 +66,11 @@ then set `PROXY_REVERSE_URL=localhost:8000`.)

## Nginx status

The [nginx status][] page is configured to run at
http://localhost:8091/nginx_status. This endpoint can be used by Datadog and
The [nginx status][] page is configured to run at
http://localhost:${STATUS_LISTEN_PORT}/nginx_status.

Set the `STATUS_LISTEN_PORT` environment variable when you start the container
(default: `8091`) to change the port. This endpoint can be used by Datadog and
other metrics collectors.

## Development
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NGINX status/stats used by datadog, et al.
server {
listen 8091;
listen {{ .Env.STATUS_LISTEN_PORT }};
Copy link
Preview

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If STATUS_LISTEN_PORT is unset, this will emit an invalid listen directive. Consider using a default/fallback (e.g., via Sprig’s default function) or validating the variable before template rendering.

Copilot uses AI. Check for mistakes.

server_name _;

access_log off;
Expand Down