I’m facing an issue where Nginx fails to start or reload due to an error:
nginx: [emerg] host not found in upstream "golang-test-server1" in /etc/nginx/http.d/golang-test-server1.conf:6
nginx: configuration file /etc/nginx/nginx.conf test failed
Here’s my current configuration:
server {
listen 80;
server_name *.golang-test-server1.localhost;
location / {
proxy_pass http://golang-test-server1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_connect_timeout 60s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
error_page 502 503 504 /custom_50x.html;
location = /custom_50x.html {
root /usr/share/nginx/html;
internal;
}
}
What I Want
Even if the upstream (golang-test-server1
) is unavailable or unresolvable during Nginx startup, I want:
- Nginx to start successfully because other services depend on it.
- A custom error page to be displayed when the backend is down.
What I Tried
-
Using a Resolver
I addedresolver 127.0.0.11
in thehttp
block (since I’m using Docker), but Nginx still fails to start with the same error. -
Upstream Block with Backup
I defined an upstream block like this:upstream golang_test_backend { server golang-test-server1; server 127.0.0.1:9999 backup; }
And updated
proxy_pass
tohttp://golang_test_backend
, but Nginx still doesn’t start ifgolang-test-server1
is unresolvable. -
Custom Error Pages
I configuredproxy_intercept_errors on;
witherror_page
directives, but the issue is Nginx won’t even start if the upstream isn’t resolvable.
Environment Details
- Nginx version:
1.x.x
- OS: Alpine Linux
- Nginx configuration directory:
/etc/nginx/http.d/
- Backend service: Dynamically assigned (Dockerized service).