# 如何为 Dify 配置 HTTP 代理(适用于无公网服务器)

**URL:** https://forum.magentochina.org/t/%E5%A6%82%E4%BD%95%E4%B8%BA-dify-%E9%85%8D%E7%BD%AE-http-%E4%BB%A3%E7%90%86%E9%80%82%E7%94%A8%E4%BA%8E%E6%97%A0%E5%85%AC%E7%BD%91%E6%9C%8D%E5%8A%A1%E5%99%A8/1030
**Category:** Uncategorized
**Tags:** ai, 代理
**Created:** [2025 年6 月 6 日 08:32 UTC](https://forum.magentochina.org/t/%E5%A6%82%E4%BD%95%E4%B8%BA-dify-%E9%85%8D%E7%BD%AE-http-%E4%BB%A3%E7%90%86%E9%80%82%E7%94%A8%E4%BA%8E%E6%97%A0%E5%85%AC%E7%BD%91%E6%9C%8D%E5%8A%A1%E5%99%A8/1030 "2025-06-06T08:32:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### 作者： ![cainiao](https://forum.magentochina.org/user_avatar/forum.magentochina.org/cainiao/32/179_2.png) [@cainiao](https://forum.magentochina.org/u/cainiao)
#### 发布日期： [2025 年6 月 6 日 08:32 UTC](https://forum.magentochina.org/t/%E5%A6%82%E4%BD%95%E4%B8%BA-dify-%E9%85%8D%E7%BD%AE-http-%E4%BB%A3%E7%90%86%E9%80%82%E7%94%A8%E4%BA%8E%E6%97%A0%E5%85%AC%E7%BD%91%E6%9C%8D%E5%8A%A1%E5%99%A8/1030/1 "2025-06-06T08:32:08Z")

</div>

Dify 默认通过 Docker 安装和管理。但在没有互联网访问能力的服务器上，Dify 默认环境并未内置代理配置。若未正确配置 HTTP 代理，后端可能会出现以下报错：

```auto
- failed to get the version of the plugin sdk: failed to find the version of the plugin sdk
- requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Run failed: [tongyi] Error: PluginInvokeError: {"args":"errortype":"ConnectTimeout","message":"HTTPSConnectionPool(host='dashscope.aliyuncs.com' port=443): Max retries exceeded with url:/api/v1/services/aigc/text-qeneration/qeneration(Caused byConnectTimeoutError u003curllib3.connection.HTTPSConnectionobject at 0x7ff595d05a90\u003e.Connection to dashscope.aliyuncs.com timed out.(connect timeout=300)))"

```

为避免此类错误，您需要为 Dify 配置代理访问互联网。

## 如何解决？

### 1. 首先确定您的代理没问题

安装好代理服务后，首先使用curl命令在宿主机进行网络联通性测试：

> curl -x http://\<代理IP\>:\<端口\> [https://www.google.com](https://www.google.com)

若代理可用，应能正常获取网页内容，然后再为docker配置代理。

### 2. 配置ssrf代理

修改dify/docker下的 docker-compose.yaml 文件:

> <https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml#L352-%23L353>

将这两个变量，替换成你的实际代理服务地址

### 3. 配置docker代理

修改dify/docker下的 docker-compose.yaml 文件:  
在根节点x-shared-env内，追加三条代理配置

```auto
HTTP_PROXY: http://172.16.0.3:1081
HTTPS_PROXY: http://172.16.0.3:1081
NO_PROXY: localhost,127.0.0.1,192.168.0.0/16,172.16.0.0/12,firecrawl-api-1, weaviate, gdrand, db, redis, web, worker,plugin_daemon

```

注意：

- 请根据您的代理 IP 地址实际替换 `172.16.0.3:1081`。
- `NO_PROXY` 列表请确保包含内部服务容器名，避免代理影响内部通信。

### 4. 重启docker

进入 Dify 安装目录 `dify/docker`，执行以下命令重建并启动容器：

> docker compose up -d --force-recreate

### 5. 验证

服务重启后，可通过浏览器或日志观察以下内容来确认代理配置是否生效：

- 插件是否能正常访问外部接口（如阿里云 DashScope）
- 后台不再报连接超时或 JSON 解码错误
- 如有问题，可进一步检查日志或与我们联系
