API url error if the port is modified to other ports in the nginx part in docker-compose.yaml
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] Please do not modify this template :) and fill in all the required fields.
Dify version
0.6.7
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
- Change the port in line 391 docker-compose.yaml in dify/docker.
- docker compose it
- Add a chat assistant
- go to the api pannel. The api is shown without the port.
- Try to access the url by adding the port to the host. It will jump to the one without port automatically.
- The web page url published is also without port, but this can be accessed if port number is added to the host.
✔️ Expected Behavior
Have access to the api no matter how the port changes.
❌ Actual Behavior
Cannot access to the api if the port is changed to neither 443 nor 80.
Hey @buptsad! I'm Dosu, a bot here to help you squash bugs, answer questions, and become a contributor. While you wait for a human maintainer, I'm taking a look at your issue and will provide a full answer shortly.
Note that this is similar to #4534 but I modified the port number to a port other than 80 and 443 because there are existing service on these ports.
docker-compose.yml,needs to modify Api: environment variables APP_WEB_URL,SERVICE_API_URL,fill in 'http://ip:nginx-port'
@buptsad
To address the issue with modifying the port in the docker-compose.yml file for a self-hosted Dify version 0.6.7 and ensure the API URL reflects the new port, you need to update the environment variables in the api and web services. Here is how you can do it:
-
Locate the
apiservice and set theAPP_WEB_URLandSERVICE_API_URLenvironment variables. -
Locate the
webservice and set theAPP_API_URLenvironment variable.
Assuming the new port for the nginx service is 8080, here is the updated configuration:
version: '3'
services:
# API service
api:
image: langgenius/dify-api:0.6.8
restart: always
environment:
MODE: api
LOG_LEVEL: INFO
SECRET_KEY: sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U
CONSOLE_WEB_URL: 'http://ip:8080'
INIT_PASSWORD: ''
CONSOLE_API_URL: 'http://ip:8080'
SERVICE_API_URL: 'http://ip:8080'
APP_WEB_URL: 'http://ip:8080'
FILES_URL: 'http://ip:8080'
MIGRATION_ENABLED: 'true'
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_USE_SSL: 'false'
REDIS_DB: 0
CELERY_BROKER_URL: redis://:difyai123456@redis:6379/1
WEB_API_CORS_ALLOW_ORIGINS: '*'
CONSOLE_CORS_ALLOW_ORIGINS: '*'
STORAGE_TYPE: local
STORAGE_LOCAL_PATH: storage
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'
VECTOR_STORE: weaviate
WEAVIATE_ENDPOINT: http://weaviate:8080
WEAVIATE_API_KEY: WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
QDRANT_URL: http://qdrant:6333
QDRANT_API_KEY: difyai123456
QDRANT_CLIENT_TIMEOUT: 20
QDRANT_GRPC_ENABLED: 'false'
QDRANT_GRPC_PORT: 6334
MILVUS_HOST: 127.0.0.1
MILVUS_PORT: 19530
MILVUS_USER: root
MILVUS_PASSWORD: Milvus
MILVUS_SECURE: 'false'
MAIL_TYPE: ''
MAIL_DEFAULT_SEND_FROM: 'YOUR EMAIL FROM (eg: no-reply <[email protected]>)'
SMTP_SERVER: ''
SMTP_PORT: 587
SMTP_USERNAME: ''
SMTP_PASSWORD: ''
SMTP_USE_TLS: 'true'
RESEND_API_KEY: ''
RESEND_API_URL: https://api.resend.com
RELYT_HOST: db
RELYT_PORT: 5432
RELYT_USER: postgres
RELYT_PASSWORD: difyai123456
RELYT_DATABASE: postgres
PGVECTOR_HOST: pgvector
PGVECTOR_PORT: 5432
PGVECTOR_USER: postgres
PGVECTOR_PASSWORD: difyai123456
PGVECTOR_DATABASE: dify
NOTION_INTEGRATION_TYPE: public
NOTION_CLIENT_SECRET: you-client-secret
NOTION_CLIENT_ID: you-client-id
NOTION_INTERNAL_SECRET: you-internal-secret
INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH: 1000
depends_on:
- db
- redis
volumes:
- ./volumes/app/storage:/app/api/storage
networks:
- ssrf_proxy_network
- default
# Frontend web application.
web:
image: langgenius/dify-web:0.6.8
restart: always
environment:
CONSOLE_API_URL: 'http://ip:8080'
APP_API_URL: 'http://ip:8080'
SENTRY_DSN: ''
# uncomment to expose dify-web port to host
# ports:
# - "3000:3000"
# 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:
- "8080:80"
#- "443:443"
networks:
ssrf_proxy_network:
driver: bridge
internal: true
In this configuration:
- The
SERVICE_API_URL,APP_WEB_URL,CONSOLE_WEB_URL,CONSOLE_API_URL, andFILES_URLin theapiservice are set tohttp://ip:8080. - The
APP_API_URLandCONSOLE_API_URLin thewebservice are set tohttp://ip:8080. - The
nginxservice is configured to expose port8080on the host, mapping it to port80in the container.
This setup ensures that the environment variables are correctly configured to reflect the new port, and the API URL will update accordingly when the port is modified.
Here are similar issues I found:
- https://github.com/langgenius/dify/issues/2374
- https://github.com/langgenius/dify/issues/4534 This issue was closed with the suggestion to ensure the Docker container running the application can communicate with the outside world by configuring the Docker network settings and updating the environment variables to reflect the correct address of the target service.
- https://github.com/langgenius/dify/issues/4007 This issue was closed with the suggestion to check the Nginx configuration, update the Docker Compose configuration, restart Docker services, and ensure no firewall or network settings are blocking access to the new port.
- https://github.com/langgenius/dify/issues/3953
Details
Sources
- When using Docker Compose to deploy, Dify cannot access the API interface.
- Bug report: API access Base URLs are incorrect, resulting in inaccessible endpoints
- The Docker type deployment failed, the installation page cannot be opened, please help.
- Nginx change of Default port and make Application agnostic about it.
- docker/docker-compose.yaml
- en/getting-started/install-self-hosted/environments.md
- api/.env.example
- api/config.py
- web/config/index.ts
About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.