nginx: [emerg] host not found in upstream "api" in /etc/nginx/conf.d/default.conf:8 #12272

Closed
opened 2026-02-21 19:06:41 -05:00 by yindo · 1 comment
Owner

Originally created by @ZelinMa557 on GitHub (Mar 27, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. git clone https://github.com/langgenius/dify.git --branch 0.15.3
  2. cd dify/docker
  3. cp .env.example .env
  4. append following lines to network config in docker-compose.yaml:
  default:
    driver: bridge
    internal: true
  1. podman-compose up -d

✔️ Expected Behavior

dify success to start

Actual Behavior

nginx container excited:

Image

nginx's log shows that:

Image

my nginx config is:

# Please do not directly edit this file. Instead, modify the .env variables related to NGINX configuration.

server {
    listen 80;
    server_name _;

    location /console/api {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location /api {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location /v1 {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location /files {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location / {
      proxy_pass http://web:3000;
      include proxy.conf;
    }

    # placeholder for acme challenge location
    

    # placeholder for https config defined in https.conf.template
    
}

I didn't modify the condig of nginx.
Does any one meet the same issue?

Originally created by @ZelinMa557 on GitHub (Mar 27, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. git clone https://github.com/langgenius/dify.git --branch 0.15.3 2. cd dify/docker 3. cp .env.example .env 4. append following lines to network config in docker-compose.yaml: ``` default: driver: bridge internal: true ``` 5. podman-compose up -d ### ✔️ Expected Behavior dify success to start ### ❌ Actual Behavior nginx container excited: <img width="1020" alt="Image" src="https://github.com/user-attachments/assets/5ef2734d-101c-488a-ba11-ee32339c971f" /> nginx's log shows that: <img width="843" alt="Image" src="https://github.com/user-attachments/assets/f8b819cc-1288-464d-abcb-ed76291822c1" /> my nginx config is: ``` # Please do not directly edit this file. Instead, modify the .env variables related to NGINX configuration. server { listen 80; server_name _; location /console/api { proxy_pass http://api:5001; include proxy.conf; } location /api { proxy_pass http://api:5001; include proxy.conf; } location /v1 { proxy_pass http://api:5001; include proxy.conf; } location /files { proxy_pass http://api:5001; include proxy.conf; } location / { proxy_pass http://web:3000; include proxy.conf; } # placeholder for acme challenge location # placeholder for https config defined in https.conf.template } ``` I didn't modify the condig of nginx. Does any one meet the same issue?
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 19:06:41 -05:00
yindo closed this issue 2026-02-21 19:06:41 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 27, 2025):

To resolve the "nginx: [emerg] host not found in upstream 'api'" error, ensure that the nginx service is connected to the same Docker network as the api service. Here are some steps you can follow:

  1. Network Configuration: Verify that both nginx and api services are on the same network. In your docker-compose.yaml, ensure that both services are connected to the default network. The internal: true setting might restrict external access, so consider removing it if not necessary.

  2. Nginx Configuration: Double-check your Nginx configuration to ensure the upstream server is correctly defined. It should reference the api service by its Docker service name, which is api.

  3. Docker Compose: Make sure all services are running correctly. Use podman-compose ps to check the status of your containers.

  4. IP Address Configuration: If the error persists, manually set the IP address of the API container in the Nginx configuration. Use the following command to find the IP address of the API container:

    podman ps -q | xargs -n 1 podman inspect --format '{{ .Name }}: {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
    

    Update the Nginx configuration by replacing http://api:5001 with http://<api-container-ip>:5001.

  5. Restart Nginx: After making changes, restart the Nginx container or reload the configuration to apply the changes.

Additionally, there are similar discussions that might be helpful:

These discussions might provide further insights or solutions applicable to your situation.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 27, 2025): <!-- Answer --> To resolve the "nginx: [emerg] host not found in upstream 'api'" error, ensure that the `nginx` service is connected to the same Docker network as the `api` service. Here are some steps you can follow: 1. **Network Configuration**: Verify that both `nginx` and `api` services are on the same network. In your `docker-compose.yaml`, ensure that both services are connected to the `default` network. The `internal: true` setting might restrict external access, so consider removing it if not necessary. 2. **Nginx Configuration**: Double-check your Nginx configuration to ensure the upstream server is correctly defined. It should reference the `api` service by its Docker service name, which is `api`. 3. **Docker Compose**: Make sure all services are running correctly. Use `podman-compose ps` to check the status of your containers. 4. **IP Address Configuration**: If the error persists, manually set the IP address of the API container in the Nginx configuration. Use the following command to find the IP address of the API container: ```bash podman ps -q | xargs -n 1 podman inspect --format '{{ .Name }}: {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ``` Update the Nginx configuration by replacing `http://api:5001` with `http://<api-container-ip>:5001`. 5. **Restart Nginx**: After making changes, restart the Nginx container or reload the configuration to apply the changes. Additionally, there are similar discussions that might be helpful: - [After upgrading from version 0.5.3 to 1.0.0, the local dify cannot be opened and a 502 bad gateway error occurs](https://github.com/langgenius/dify/discussions/14965) <sup>[[1]](https://github.com/langgenius/dify/discussions/14965)</sup>. - [How to setup nginx config, now call API got Bad Gateway](https://github.com/langgenius/dify/discussions/9239) <sup>[[2]](https://github.com/langgenius/dify/discussions/9239)</sup>. These discussions might provide further insights or solutions applicable to your situation. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e19429d9-6b86-41ce-bd1f-0472d5d0803c?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12272