# Nginx: nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:5

**Code:** `nginx: host not found in upstream` · **Category:** Nginx / Apache · **Seen on:** Nginx, Docker

Nginx couldn't resolve the hostname in an `upstream`/`proxy_pass` at startup.

## Meaning

Nginx resolves upstream names when it loads the config. In Docker Compose the service must exist and be on the same network and started; if the backend isn't up yet nginx exits. Use `resolver 127.0.0.11;` with a variable in `proxy_pass` for lazy resolution, or `depends_on` + restart policy.

## Common causes

- Backend container not started/not on the same network
- Typo in the host name
- DNS not available at nginx startup
- Static resolution at load time
- Kubernetes service not created

## Quick fix

1. Start the backend first (`depends_on`) and verify the service name
2. Use lazy resolution: `resolver 127.0.0.11 valid=10s; set $up http://app:3000; proxy_pass $up;`
3. Check `docker network inspect`

## Detailed fix by platform

### Docker

1. `docker compose exec nginx getent hosts app`

## How to diagnose

1. **Name** — Spelled right?
2. **Network** — Same?
3. **Resolution** — At startup?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nginx-apache/nginx-host-not-found-in-upstream)
