我在使用虚拟机Ubuntu本地部署了dify后,使用openai的api key,无法连接 #52

Closed
opened 2026-02-16 11:19:37 -05:00 by yindo · 4 comments
Owner

Originally created by @554159290 on GitHub (Jan 24, 2025).

Image
使用虚拟机安装ubuntu22.04,通过宿主机代理方式让虚拟机可以连接外网,但是在添加openai的api key时报错,使用中国境内的ai模型可以正常添加,请问怎么解决?

Originally created by @554159290 on GitHub (Jan 24, 2025). ![Image](https://github.com/user-attachments/assets/bb2d50ae-4b9a-4d0d-82c1-185e393e03c9) 使用虚拟机安装ubuntu22.04,通过宿主机代理方式让虚拟机可以连接外网,但是在添加openai的api key时报错,使用中国境内的ai模型可以正常添加,请问怎么解决?
yindo added the bug label 2026-02-16 11:19:37 -05:00
yindo closed this issue 2026-02-16 11:19:37 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 24, 2025):

@554159290 你好!我是Dosu,一个可以帮助你解决错误、回答问题并成为贡献者的机器人。在等待人类维护者的期间,我将会提供帮助。

要解决在虚拟机Ubuntu本地部署Dify时添加OpenAI API密钥时的连接错误,您需要检查代理设置。这个问题通常是由于代理设置干扰了与OpenAI服务器的连接。请确保您的代理设置正确配置,以允许连接到OpenAI的API。

您可以尝试以下步骤:

  1. 确保在环境中正确设置了HTTP_PROXYHTTPS_PROXY,以便通过代理访问OpenAI的API。例如,如果代理部署在主机上,您可以在Docker容器中使用主机的地址(例如,http://192.168.1.100:7890http://172.17.0.1:7890[1]

  2. 在Dify中,您可以通过设置 --> 模型提供商 --> OpenAI --> 编辑API来指定OpenAI的自定义API域名。这对于需要通过特定服务器访问OpenAI API的情况特别有用[2]

请确保您的代理配置允许对OpenAI API的连接,并根据需要调整设置。

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Jan 24, 2025): <!-- Greeting --> @554159290 你好!我是[Dosu](https://dosu.dev),一个可以帮助你解决错误、回答问题并成为贡献者的机器人。在等待人类维护者的期间,我将会提供帮助。 <!-- Answer --> 要解决在虚拟机Ubuntu本地部署Dify时添加OpenAI API密钥时的连接错误,您需要检查代理设置。这个问题通常是由于代理设置干扰了与OpenAI服务器的连接。请确保您的代理设置正确配置,以允许连接到OpenAI的API。 您可以尝试以下步骤: 1. 确保在环境中正确设置了`HTTP_PROXY`和`HTTPS_PROXY`,以便通过代理访问OpenAI的API。例如,如果代理部署在主机上,您可以在Docker容器中使用主机的地址(例如,`http://192.168.1.100:7890`或`http://172.17.0.1:7890`)<sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/jp/getting-started/install-self-hosted/environments.md)</sup>。 2. 在Dify中,您可以通过**设置 --> 模型提供商 --> OpenAI --> 编辑API**来指定OpenAI的自定义API域名。这对于需要通过特定服务器访问OpenAI API的情况特别有用<sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/learn-more/faq/use-llms-faq.md)</sup>。 请确保您的代理配置允许对OpenAI API的连接,并根据需要调整设置。 <!-- 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/1521f4a5-6040-4736-9284-c6c07eb087b1?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/1521f4a5-6040-4736-9284-c6c07eb087b1?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/1521f4a5-6040-4736-9284-c6c07eb087b1?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/1521f4a5-6040-4736-9284-c6c07eb087b1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1521f4a5-6040-4736-9284-c6c07eb087b1?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/1521f4a5-6040-4736-9284-c6c07eb087b1?feedback_type=other)</sup>
Author
Owner

@554159290 commented on GitHub (Jan 24, 2025):

这是宿主机的IP:

Image

这是虚拟机设置的代理:

Image

仍然是连接时报错

@554159290 commented on GitHub (Jan 24, 2025): 这是宿主机的IP: ![Image](https://github.com/user-attachments/assets/82ae454f-088a-437e-b60d-dd5125c1c2d2) 这是虚拟机设置的代理: ![Image](https://github.com/user-attachments/assets/3b3b719e-712c-4f9d-b10e-61bbf3ae0802) 仍然是连接时报错
Author
Owner

@ghostxu97 commented on GitHub (Feb 16, 2025):

+1,插个眼

@ghostxu97 commented on GitHub (Feb 16, 2025): +1,插个眼
Author
Owner

@AllenWriter commented on GitHub (Mar 2, 2025):

Hi,

The documentation repository doesn’t cover network-related issues in detail. However, as a friendly suggestion, configuring OpenAI’s proxy API to route requests through specific ports, rather than directly accessing OpenAI’s ports, can help mitigate most network issues.

Hope this helps! Let us know if you have any other questions.

@AllenWriter commented on GitHub (Mar 2, 2025): Hi, The documentation repository doesn’t cover network-related issues in detail. However, as a friendly suggestion, configuring OpenAI’s proxy API to route requests through specific ports, rather than directly accessing OpenAI’s ports, can help mitigate most network issues. Hope this helps! Let us know if you have any other questions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs-archived#52