my server is on proxy, but dify can't access the big model api, reporting an error:“Connection to dashscope.aliyuncs.com timed out.” #4292

Closed
opened 2026-02-21 18:05:35 -05:00 by yindo · 4 comments
Owner

Originally created by @JunDaTang on GitHub (Jun 27, 2024).

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).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

api_1 | ERROR:dashscope:HTTPSConnectionPool(host='dashscope.aliyuncs.com', port=443): Max retries exceeded with url: /api/v1/services/aigc/text-generation/generation (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f61280f0340>, 'Connection to dashscope.aliyuncs.com timed out. (connect timeout=300)'))

image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @JunDaTang on GitHub (Jun 27, 2024). ### Self Checks - [ ] 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). - [ ] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [ ] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [ ] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [ ] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.10 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce api_1 | ERROR:dashscope:HTTPSConnectionPool(host='dashscope.aliyuncs.com', port=443): Max retries exceeded with url: /api/v1/services/aigc/text-generation/generation (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f61280f0340>, 'Connection to dashscope.aliyuncs.com timed out. (connect timeout=300)')) ![image](https://github.com/langgenius/dify/assets/15319232/2ad1025f-99c9-404a-a125-e107baae99f3) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:05:35 -05:00
yindo closed this issue 2026-02-21 18:05:35 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 27, 2024):

@JunDaTang Hello there! I'm here to assist you with bug fixes, answer questions, and guide you on becoming a contributor. Let's get this issue resolved!

To resolve the connection timeout issue to dashscope.aliyuncs.com when running Dify version 0.6.10 on a self-hosted server behind a proxy using Docker, you need to ensure that your Docker containers are correctly configured to use the proxy. You can achieve this by setting the HTTP_PROXY and HTTPS_PROXY environment variables in your Docker Compose file.

Here is an example of how you can modify your docker-compose.yaml to include the proxy settings:

version: '3.8'

services:
  # The nginx reverse proxy.
  nginx:
    image: nginx:latest
    restart: always
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/proxy.conf:/etc/nginx/proxy.conf
      - ./nginx/conf.d:/etc/nginx/conf.d
      #- ./nginx/ssl:/etc/ssl
    depends_on:
      - api
      - web
    ports:
      - "80:80"
      #- "443:443"
    environment:
      HTTP_PROXY: 'http://your-proxy-server:port'
      HTTPS_PROXY: 'http://your-proxy-server:port'

  # The Celery worker for processing the queue.
  worker:
    image: langgenius/dify-api:0.6.11
    restart: always
    environment:
      CONSOLE_WEB_URL: ''
      MODE: worker
      LOG_LEVEL: INFO
      SECRET_KEY: sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U
      DB_USERNAME: postgres
      DB_PASSWORD: difyai123456
      DB_HOST: db
      DB_PORT: 5432
      DB_DATABASE: dify
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_USERNAME: ''
      REDIS_PASSWORD: difyai123456
      REDIS_DB: 0
      REDIS_USE_SSL: 'false'
      CELERY_BROKER_URL: redis://:difyai123456@redis:6379/1
      STORAGE_TYPE: local
      STORAGE_LOCAL_PATH: storage
      S3_USE_AWS_MANAGED_IAM: 'false'
      S3_ENDPOINT: 'https://xxx.r2.cloudflarestorage.com'
      S3_BUCKET_NAME: 'difyai'
      S3_ACCESS_KEY: 'ak-difyai'
      S3_SECRET_KEY: 'sk-difyai'
      S3_REGION: 'us-east-1'
      AZURE_BLOB_ACCOUNT_NAME: 'difyai'
      AZURE_BLOB_ACCOUNT_KEY: 'difyai'
      AZURE_BLOB_CONTAINER_NAME: 'difyai-container'
      AZURE_BLOB_ACCOUNT_URL: 'https://<your_account_name>.blob.core.windows.net'
      GOOGLE_STORAGE_BUCKET_NAME: 'yout-bucket-name'
      GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64: 'your-google-service-account-json-base64-string'
      HTTP_PROXY: 'http://your-proxy-server:port'
      HTTPS_PROXY: 'http://your-proxy-server:port'

  # The DifySandbox
  sandbox:
    image: langgenius/dify-sandbox:0.2.1
    restart: always
    environment:
      API_KEY: dify-sandbox
      GIN_MODE: 'release'
      WORKER_TIMEOUT: 15
      ENABLE_NETWORK: 'true'
      HTTP_PROXY: 'http://ssrf_proxy:3128'
      HTTPS_PROXY: 'http://ssrf_proxy:3128'
      SANDBOX_PORT: 8194
    volumes:
      - ./volumes/sandbox/dependencies:/dependencies
    networks:
      - ssrf_proxy_network

  # ssrf_proxy server
  ssrf_proxy:
    image: ubuntu/squid:latest
    restart: always
    ports:
      - "3128:3128"
      - "8194:8194"
    volumes:
      - ./volumes/ssrf_proxy/squid.conf:/etc/squid/squid.conf
    networks:
      - ssrf_proxy_network
      - default

  # Other services...
  # Add the HTTP_PROXY and HTTPS_PROXY environment variables to other services as needed.

Replace http://your-proxy-server:port with the actual address and port of your proxy server. This configuration will ensure that the services use the proxy to connect to external URLs, which should help resolve the connection timeout issue to dashscope.aliyuncs.com.

Additionally, ensure that the HTTP_PROXY and HTTPS_PROXY environment variables are correctly set in your Docker environment. According to the Dify documentation, if the proxy is deployed on the host machine (e.g., http://127.0.0.1:7890), the proxy address should be the host's internal Docker network address (e.g., http://192.168.1.100:7890 or http://172.17.0.1:7890) [1][2][3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 27, 2024): <!-- Greeting --> @JunDaTang Hello there! I'm here to assist you with bug fixes, answer questions, and guide you on becoming a contributor. Let's get this issue resolved! <!-- Answer --> To resolve the connection timeout issue to `dashscope.aliyuncs.com` when running Dify version 0.6.10 on a self-hosted server behind a proxy using Docker, you need to ensure that your Docker containers are correctly configured to use the proxy. You can achieve this by setting the `HTTP_PROXY` and `HTTPS_PROXY` environment variables in your Docker Compose file. Here is an example of how you can modify your `docker-compose.yaml` to include the proxy settings: ```yaml version: '3.8' services: # The nginx reverse proxy. nginx: image: nginx:latest restart: always volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/proxy.conf:/etc/nginx/proxy.conf - ./nginx/conf.d:/etc/nginx/conf.d #- ./nginx/ssl:/etc/ssl depends_on: - api - web ports: - "80:80" #- "443:443" environment: HTTP_PROXY: 'http://your-proxy-server:port' HTTPS_PROXY: 'http://your-proxy-server:port' # The Celery worker for processing the queue. worker: image: langgenius/dify-api:0.6.11 restart: always environment: CONSOLE_WEB_URL: '' MODE: worker LOG_LEVEL: INFO SECRET_KEY: sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U DB_USERNAME: postgres DB_PASSWORD: difyai123456 DB_HOST: db DB_PORT: 5432 DB_DATABASE: dify REDIS_HOST: redis REDIS_PORT: 6379 REDIS_USERNAME: '' REDIS_PASSWORD: difyai123456 REDIS_DB: 0 REDIS_USE_SSL: 'false' CELERY_BROKER_URL: redis://:difyai123456@redis:6379/1 STORAGE_TYPE: local STORAGE_LOCAL_PATH: storage S3_USE_AWS_MANAGED_IAM: 'false' S3_ENDPOINT: 'https://xxx.r2.cloudflarestorage.com' S3_BUCKET_NAME: 'difyai' S3_ACCESS_KEY: 'ak-difyai' S3_SECRET_KEY: 'sk-difyai' S3_REGION: 'us-east-1' AZURE_BLOB_ACCOUNT_NAME: 'difyai' AZURE_BLOB_ACCOUNT_KEY: 'difyai' AZURE_BLOB_CONTAINER_NAME: 'difyai-container' AZURE_BLOB_ACCOUNT_URL: 'https://<your_account_name>.blob.core.windows.net' GOOGLE_STORAGE_BUCKET_NAME: 'yout-bucket-name' GOOGLE_STORAGE_SERVICE_ACCOUNT_JSON_BASE64: 'your-google-service-account-json-base64-string' HTTP_PROXY: 'http://your-proxy-server:port' HTTPS_PROXY: 'http://your-proxy-server:port' # The DifySandbox sandbox: image: langgenius/dify-sandbox:0.2.1 restart: always environment: API_KEY: dify-sandbox GIN_MODE: 'release' WORKER_TIMEOUT: 15 ENABLE_NETWORK: 'true' HTTP_PROXY: 'http://ssrf_proxy:3128' HTTPS_PROXY: 'http://ssrf_proxy:3128' SANDBOX_PORT: 8194 volumes: - ./volumes/sandbox/dependencies:/dependencies networks: - ssrf_proxy_network # ssrf_proxy server ssrf_proxy: image: ubuntu/squid:latest restart: always ports: - "3128:3128" - "8194:8194" volumes: - ./volumes/ssrf_proxy/squid.conf:/etc/squid/squid.conf networks: - ssrf_proxy_network - default # Other services... # Add the HTTP_PROXY and HTTPS_PROXY environment variables to other services as needed. ``` Replace `http://your-proxy-server:port` with the actual address and port of your proxy server. This configuration will ensure that the services use the proxy to connect to external URLs, which should help resolve the connection timeout issue to `dashscope.aliyuncs.com`. Additionally, ensure that the `HTTP_PROXY` and `HTTPS_PROXY` environment variables are correctly set in your Docker environment. According to the Dify documentation, if the proxy is deployed on the host machine (e.g., `http://127.0.0.1:7890`), the proxy address should be the host's internal Docker network address (e.g., `http://192.168.1.100:7890` or `http://172.17.0.1:7890`) <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.middleware.yaml)</sup><sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/getting-started/install-self-hosted/environments.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Jun 27, 2024):

I don't think there is a need for using proxy for dashscope.aliyuncs.com.

@crazywoola commented on GitHub (Jun 27, 2024): I don't think there is a need for using proxy for `dashscope.aliyuncs.com`.
Author
Owner

@zhangzw16 commented on GitHub (Jun 27, 2024):

I encountered the same problem and solved it using the following method. You can try it too.

Create the ~/.docker/config.json file as follows:

{
    "proxies":
    {
      "default":
      {
        "httpProxy": "http://172.17.0.1:9998",
        "httpsProxy": "http://172.17.0.1:9998",
        "noProxy": "localhost,127.0.0.1,.example.com,weaviate,sandbox"
      }
    }
}

The weaviate and sandbox part may or may not be needed, but directly using http://weaviate:8080 in docker-compose.yaml line 114 might cause connection errors to the vector DB if not included. Also, 9998 is the VPN port number and might need to be modified accordingly. http://172.17.0.1 is the default host's internal Docker network address.

After editing the file, then restart docker by

docker compose down
dcoker compose up -d
@zhangzw16 commented on GitHub (Jun 27, 2024): I encountered the same problem and solved it using the following method. You can try it too. Create the `~/.docker/config.json` file as follows: ``` { "proxies": { "default": { "httpProxy": "http://172.17.0.1:9998", "httpsProxy": "http://172.17.0.1:9998", "noProxy": "localhost,127.0.0.1,.example.com,weaviate,sandbox" } } } ``` The `weaviate` and `sandbox` part may or may not be needed, but directly using `http://weaviate:8080` in `docker-compose.yaml` line 114 might cause connection errors to the vector DB if not included. Also, `9998` is the **VPN port number** and might need to be modified accordingly. `http://172.17.0.1` is the default host's internal Docker network address. After editing the file, then restart docker by ``` bash docker compose down dcoker compose up -d ```
Author
Owner

@crazywoola commented on GitHub (Jun 29, 2024):

See this also https://github.com/langgenius/dify/issues/5686#issuecomment-2198395207

@crazywoola commented on GitHub (Jun 29, 2024): See this also https://github.com/langgenius/dify/issues/5686#issuecomment-2198395207
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4292