dify的docker服務(wù)請(qǐng)求內(nèi)網(wǎng)服務(wù)器遇到的問(wèn)題
接上一篇文章: http://www.rzrgm.cn/neozheng/p/18400589
我有一臺(tái) 10.xxx.20.162 的內(nèi)網(wǎng)服務(wù)器運(yùn)行著 dify 的 docker compose 服務(wù),又起了一臺(tái) 10.xxx.41.11 的內(nèi)網(wǎng)服務(wù)器用來(lái)運(yùn)行 ollama 大模型。
我是通過(guò) 手動(dòng)的方式安裝的 ollama,在運(yùn)行ollama的時(shí)候遇到一個(gè)問(wèn)題: ollama 只監(jiān)聽(tīng)了 `127.0.0.1` 的地址。經(jīng)過(guò)查詢(xún)得知,要想把監(jiān)聽(tīng)地址改成 `0.0.0.0`,需要新建ollama的配置文件并通過(guò) `systemctl` 的方式啟動(dòng)。但我的服務(wù)器用 systemctl 啟動(dòng) ollama 又一直失敗,所以只能用 `ollama serve` 的方式啟動(dòng),這種方式啟動(dòng)的話,可以先在環(huán)境變量中配置好ollama的監(jiān)聽(tīng)地址,如下:
export OLLAMA_HOST=0.0.0.0:11434
通過(guò)這種方式就能在 10.xxx.20.162 的內(nèi)網(wǎng)服務(wù)器 成功訪問(wèn) 10.xxx.41.11 的ollama服務(wù)了,如下:
curl http://localhost:11434/api/generate -d '{ "model": "llama3.2", "prompt":"Why is the sky blue?" }'
但在公司電腦的瀏覽器上訪問(wèn)10.xxx.20.162 上的dify服務(wù)時(shí), ollama 的模型在dify中一直添加失敗。 最后意識(shí)到應(yīng)該是 代理的問(wèn)題,就對(duì) docker-compose.yaml做了如下修改:
... services: # API service api: image: langgenius/dify-api:0.7.1 restart: always environment: # Use the shared environment variables. <<: *shared-api-worker-env # Startup mode, 'api' starts the API server. MODE: api # 設(shè)置代理 HTTP_PROXY: http://my-proxy.com:3128 HTTPS_PROXY: http://my-proxy.com:3128 # 不走代理的情況: 把 weaviate 服務(wù)添加到里面 NO_PROXY: localhost,127.0.0.1,weaviate,10.xxx.41.11 depends_on: - db - redis volumes: # Mount the storage directory to the container, for storing user files. - ./volumes/app/storage:/app/api/storage networks: - ssrf_proxy_network - default # worker service # The Celery worker for processing the queue. worker: image: langgenius/dify-api:0.7.1 restart: always environment: # Use the shared environment variables. <<: *shared-api-worker-env # Startup mode, 'worker' starts the Celery worker for processing the queue. MODE: worker # 設(shè)置代理 HTTP_PROXY: http://my-proxy.com:3128 HTTPS_PROXY: http://my-proxy.com:3128 # 不走代理的情況: 把 weaviate 服務(wù)添加到里面 NO_PROXY: localhost,127.0.0.1,weaviate,10.xxx.41.11 depends_on: - db - redis volumes: # Mount the storage directory to the container, for storing user files. - ./volumes/app/storage:/app/api/storage networks: - ssrf_proxy_network - default # dify 的其他服務(wù)就不需要配置代理的設(shè)置了 ...
通過(guò)在 NO_PROXY 中添加 10.xxx.41.11,就表示訪問(wèn)它的時(shí)候不要走代理。 這樣子,在dify頁(yè)面上添加 ollama模型失敗的問(wèn)題就解決了

浙公網(wǎng)安備 33010602011771號(hào)