100 lines
2.3 KiB
Markdown
100 lines
2.3 KiB
Markdown
# Proxy Reminder: Race Management Upstream Resilience
|
|
|
|
## Problem
|
|
|
|
`mnmsoft_proxy` currently fails hard at nginx startup if the upstream hostname
|
|
`race-management-web` is not resolvable at config-parse time.
|
|
|
|
Observed failure:
|
|
|
|
```text
|
|
host not found in upstream "race-management-web" in /etc/nginx/conf.d/default.conf
|
|
```
|
|
|
|
This caused the proxy container to restart in a loop whenever the
|
|
`race-management-web` container was down or not yet attached to the shared
|
|
Docker network.
|
|
|
|
## What Was Already Fixed
|
|
|
|
In `/opt/docker/apps/race-management/docker-compose.yml`:
|
|
|
|
- `db` now uses `restart: unless-stopped`
|
|
- `web` now uses `restart: unless-stopped`
|
|
|
|
That reduces the chance of the backend staying down, but the proxy should still
|
|
be made tolerant of temporary upstream absence.
|
|
|
|
## What Needs To Be Done In Proxy
|
|
|
|
Relevant proxy files:
|
|
|
|
- `/opt/docker/apps/proxy/generated/default.conf`
|
|
- possibly `/opt/docker/apps/proxy/nginx/nginx.conf`
|
|
|
|
### Goal
|
|
|
|
Avoid nginx resolving `race-management-web` only once at startup.
|
|
Instead, make nginx resolve through Docker DNS at request time or with a
|
|
short-lived resolver cache.
|
|
|
|
### Recommended Approach
|
|
|
|
Use Docker's internal DNS resolver and proxy through a variable.
|
|
|
|
Typical pattern:
|
|
|
|
```nginx
|
|
resolver 127.0.0.11 valid=10s;
|
|
|
|
location / {
|
|
set $race_management_upstream http://race-management-web:8000;
|
|
proxy_pass $race_management_upstream;
|
|
}
|
|
```
|
|
|
|
### Why
|
|
|
|
With a static upstream like:
|
|
|
|
```nginx
|
|
proxy_pass http://race-management-web:8000;
|
|
```
|
|
|
|
nginx may try to resolve the hostname during startup/config load. If the
|
|
container is absent at that exact moment, nginx exits and the proxy restarts.
|
|
|
|
Using `resolver 127.0.0.11` plus a variable makes nginx rely on Docker DNS more
|
|
safely at runtime.
|
|
|
|
## Also Clean Up
|
|
|
|
The proxy logs also show this warning:
|
|
|
|
```text
|
|
the "listen ... http2" directive is deprecated
|
|
```
|
|
|
|
If present, replace patterns like:
|
|
|
|
```nginx
|
|
listen 443 ssl http2;
|
|
```
|
|
|
|
with the newer form appropriate for the installed nginx version.
|
|
|
|
## After Editing
|
|
|
|
Reload/recreate the proxy stack and verify:
|
|
|
|
```bash
|
|
cd /opt/docker/apps/proxy
|
|
docker compose up -d
|
|
docker logs --tail 100 mnmsoft_proxy
|
|
```
|
|
|
|
Expected result:
|
|
|
|
- proxy stays up even if `race-management-web` is briefly unavailable during startup
|
|
- no more `host not found in upstream "race-management-web"` fatal error
|