dify icon indicating copy to clipboard operation
dify copied to clipboard

Deploying with Docker and using a proxy openai address cannot use this model and will result in nginx errors

Open Rosejacka opened this issue 6 months ago • 4 comments

Self Checks

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

Dify version

1.4.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Deploying with Docker and using a proxy openai address cannot use this model and will result in nginx errors

✔️ Expected Behavior

Deploying with Docker and using a proxy openai address cannot use this model and will result in nginx errors

❌ Actual Behavior

No response

Rosejacka avatar May 30 '25 13:05 Rosejacka

Image

Rosejacka avatar May 30 '25 13:05 Rosejacka

The 404 Not Found error from Nginx when using a proxy OpenAI address in your Docker deployment is likely due to a mismatch between Dify’s internal routing and the structure or expectations of your proxy service. Dify’s Nginx configuration only proxies specific paths (like /api, /v1) to internal services and does not forward requests directly to external OpenAI or proxy endpoints. Any proxying to OpenAI must be handled by the backend using environment variables such as HOSTED_OPENAI_API_BASE or SSRF_PROXY_* settings, not at the Nginx layer. If these are misconfigured, requests may not reach your proxy as intended, or your proxy may return a 404 if the path does not match what it expects. Troubleshooting should focus on ensuring that the backend’s OpenAI/proxy URL settings align with your proxy’s expected URL structure and that Nginx is not intercepting or misrouting these requests. For more details on the relevant configuration and separation of concerns, see this reference.

If you are using a custom base path or subdirectory, you may need to rebuild the Dify web Docker image with the correct NEXT_PUBLIC_BASE_PATH and update your Docker and Nginx configuration accordingly to avoid static asset 404s. See this issue for guidance.

Also, if you are running Dify behind a reverse proxy, ensure that the Host header is set to $http_host in your Nginx proxy configuration and that RESPECT_XFORWARD_HEADERS_ENABLED is set to true in your docker-compose.yaml to handle X-Forwarded headers correctly. See this solution.

In summary: check your backend proxy/OpenAI URL settings, ensure they match your proxy’s expectations, and verify that Nginx is not misrouting requests intended for the backend. If you share your relevant environment and proxy configuration, more targeted advice may be possible.

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar May 30 '25 13:05 dosubot[bot]

So should I directly modify the environment variables?@dosu

Rosejacka avatar May 30 '25 13:05 Rosejacka

Yes, in your case, you should directly modify the relevant environment variables in your Docker deployment to resolve the Nginx 404 error when using a proxy OpenAI address. Dify handles proxying to OpenAI (or a proxy for it) at the application backend level, not via Nginx. The key environment variables to review and adjust are:

  • HOSTED_OPENAI_API_BASE: Set this to the base URL of your OpenAI proxy endpoint. This tells Dify’s backend where to send OpenAI API requests, ensuring they go through your proxy instead of directly to OpenAI.
  • HOSTED_OPENAI_API_KEY and HOSTED_OPENAI_API_ORGANIZATION: Set these as needed for authentication with your proxy or OpenAI service, if required.
  • SSRF_PROXY_ALL_URL, SSRF_PROXY_HTTP_URL, and SSRF_PROXY_HTTPS_URL: If your setup requires routing all HTTP/HTTPS requests through a proxy (for example, for security or compliance), set these to your proxy URLs. These control how Dify proxies outbound requests and can affect routing if misconfigured, potentially leading to 404 errors if the proxy does not recognize the request path or format.

You can set these variables in your Docker Compose file or .env file, then restart your containers for the changes to take effect. For example:

HOSTED_OPENAI_API_BASE=https://your-proxy.example.com/v1
HOSTED_OPENAI_API_KEY=your-key
HOSTED_OPENAI_API_ORGANIZATION=your-org-id
SSRF_PROXY_HTTP_URL=http://your-http-proxy:port
SSRF_PROXY_HTTPS_URL=http://your-https-proxy:port

Make sure the URLs and credentials match your proxy’s expectations. If your proxy expects a specific path structure, ensure HOSTED_OPENAI_API_BASE matches it exactly. If you are behind a reverse proxy (like Nginx), also consider enabling RESPECT_XFORWARD_HEADERS_ENABLED to ensure correct handling of forwarded headers.

These changes only affect how the backend routes requests and do not require changes to the Nginx configuration itself. For more details, see the relevant code and configuration references:

If you continue to see 404 errors, double-check that the proxy endpoint is reachable from within your Docker network and that the path and authentication details are correct.

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar May 30 '25 13:05 dosubot[bot]