Update nginx configs for reresolving proxy endpoints.
This commit is contained in:
parent
3ad7ebf889
commit
fc217643dc
2 changed files with 28 additions and 12 deletions
|
|
@ -3,9 +3,11 @@
|
||||||
# forwards to the api service. Same envsubst vars as the TLS template:
|
# forwards to the api service. Same envsubst vars as the TLS template:
|
||||||
# NGINX_SERVER_NAME (expanded by the nginx Docker entrypoint).
|
# NGINX_SERVER_NAME (expanded by the nginx Docker entrypoint).
|
||||||
|
|
||||||
upstream api {
|
# Dynamic DNS resolution: when the API container is recreated it gets a new
|
||||||
server api:8000;
|
# IP. Using a variable with proxy_pass forces nginx to re-resolve `api`
|
||||||
}
|
# against Docker's embedded DNS every `valid=` interval instead of caching the
|
||||||
|
# address at startup.
|
||||||
|
resolver 127.0.0.11 valid=10s;
|
||||||
|
|
||||||
log_format contract_check '$remote_addr - $remote_user [$time_local] "$request" '
|
log_format contract_check '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
'$status $body_bytes_sent "$http_referer" '
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
|
@ -27,7 +29,9 @@ server {
|
||||||
server_name ${NGINX_SERVER_NAME} localhost;
|
server_name ${NGINX_SERVER_NAME} localhost;
|
||||||
|
|
||||||
location ~ ^/(healthz|readyz|metrics|api/|admin/|docs|openapi.json) {
|
location ~ ^/(healthz|readyz|metrics|api/|admin/|docs|openapi.json) {
|
||||||
proxy_pass http://api;
|
# Variable forces dynamic DNS resolution for `api`.
|
||||||
|
set $api http://api:8000;
|
||||||
|
proxy_pass $api;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|
@ -44,7 +48,9 @@ server {
|
||||||
}
|
}
|
||||||
|
|
||||||
location /webhook/ {
|
location /webhook/ {
|
||||||
proxy_pass http://api/api/v1/webhooks/;
|
# Variable forces dynamic DNS resolution for `api`.
|
||||||
|
set $api http://api:8000;
|
||||||
|
proxy_pass $api/api/v1/webhooks/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,17 @@
|
||||||
# Do not run `nginx -t` directly on this .template file; render it first with
|
# Do not run `nginx -t` directly on this .template file; render it first with
|
||||||
# envsubst or start the container.
|
# envsubst or start the container.
|
||||||
|
|
||||||
# ── Upstreams ───────────────────────────────────────────────────────────────
|
# ── Dynamic upstream resolution ─────────────────────────────────────────────
|
||||||
# In Docker Compose the `api` hostname resolves via the project network.
|
# In Docker Compose the `api` hostname must be re-resolved when the API
|
||||||
upstream api {
|
# container is recreated (it gets a new IP). By default nginx resolves an
|
||||||
server api:8000;
|
# upstream hostname once at startup and caches it forever, so after a deploy the
|
||||||
}
|
# edge proxy would keep trying the old API IP. Using a variable with
|
||||||
|
# proxy_pass forces nginx to re-resolve `api` against Docker's embedded DNS
|
||||||
|
# every `valid=` interval.
|
||||||
|
#
|
||||||
|
# 127.0.0.11 is Docker's internal resolver (available inside containers).
|
||||||
|
# If it is unreachable, increase `valid=` or set an explicit resolver address.
|
||||||
|
resolver 127.0.0.11 valid=10s;
|
||||||
|
|
||||||
# ── Logging ─────────────────────────────────────────────────────────────────
|
# ── Logging ─────────────────────────────────────────────────────────────────
|
||||||
log_format contract_check '$remote_addr - $remote_user [$time_local] "$request" '
|
log_format contract_check '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
|
@ -65,7 +71,9 @@ server {
|
||||||
# lock it down at the firewall (or remove this block if metrics must stay
|
# lock it down at the firewall (or remove this block if metrics must stay
|
||||||
# private and are scraped by an in-compose Prometheus).
|
# private and are scraped by an in-compose Prometheus).
|
||||||
location ~ ^/(healthz|readyz|metrics|api/|admin/|docs|openapi.json) {
|
location ~ ^/(healthz|readyz|metrics|api/|admin/|docs|openapi.json) {
|
||||||
proxy_pass http://api;
|
# Variable forces dynamic DNS resolution for `api`.
|
||||||
|
set $api http://api:8000;
|
||||||
|
proxy_pass $api;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|
@ -85,7 +93,9 @@ server {
|
||||||
# Webhook endpoint for future payment providers (ЮKassa, etc.).
|
# Webhook endpoint for future payment providers (ЮKassa, etc.).
|
||||||
# Kept separate so it's easy to add IP allow-listing or extra logging.
|
# Kept separate so it's easy to add IP allow-listing or extra logging.
|
||||||
location /webhook/ {
|
location /webhook/ {
|
||||||
proxy_pass http://api/api/v1/webhooks/;
|
# Variable forces dynamic DNS resolution for `api`.
|
||||||
|
set $api http://api:8000;
|
||||||
|
proxy_pass $api/api/v1/webhooks/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue