Using $variable:port with no path appended forces DNS re-resolution while nginx still forwards the full original request URI unchanged. Previous attempt ($upstream/api/) was dropping the request path. Co-Authored-By: Paperclip <[email protected]>
25 lines
727 B
Nginx Configuration File
25 lines
727 B
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
# Use Docker's embedded DNS so upstream names are re-resolved dynamically.
|
|
# Using a variable in proxy_pass forces nginx to use this resolver on each request.
|
|
resolver 127.0.0.11 valid=5s;
|
|
|
|
location /api/ {
|
|
set $api_upstream api;
|
|
proxy_pass http://$api_upstream:8000;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 30s;
|
|
proxy_connect_timeout 5s;
|
|
}
|
|
|
|
location / {
|
|
root /usr/share/nginx/html;
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|