dify 配置访问前缀
1. docker启动
请自行百度
2. 修改 dify 配置
1. 修改 .env 文件
在docker目录下找到.env文件,找到EXPOSE_NGINX_PORT,修改EXPOSE_NGINX_PORT和EXPOSE_NGINX_SSL_PORT后面的端口号(后续使用8881端口演示):
# ------------------------------
# Docker Compose Service Expose Host Port Configurations
# ------------------------------
EXPOSE_NGINX_PORT=8881 #80
EXPOSE_NGINX_SSL_PORT=8882 #443
2. 修改docker.compose.yaml
# Frontend web application.web:#增加下面build配置build:context: ../webdockerfile: Dockerfile#移除下面这行imageimage: langgenius/dify-web:0.15.3 restart: alwaysenvironment:CONSOLE_API_URL: ${CONSOLE_API_URL:-}APP_API_URL: ${APP_API_URL:-}SENTRY_DSN: ${WEB_SENTRY_DSN:-}NEXT_TELEMETRY_DISABLED: ${NEXT_TELEMETRY_DISABLED:-0}TEXT_GENERATION_TIMEOUT_MS: ${TEXT_GENERATION_TIMEOUT_MS:-60000}CSP_WHITELIST: ${CSP_WHITELIST:-}TOP_K_MAX_VALUE: ${TOP_K_MAX_VALUE:-}INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH: ${INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH:-}
3. 修改 Next.js 配置
web/next.config.js
async redirects() {return [{source: '/',destination: '/apps',permanent: false,},]},output: 'standalone',//增加下面一行basePath: '/dify',
4. 重启dify
docker compose down
docker compose up -d --build
5. nginx 配置
location ~* ^/(dify|console|api) {proxy_pass http://localhost:8881;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $host:$server_port;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_http_version 1.1;add_header 'Access-Control-Allow-Origin' '*'; # 解决 CORS 问题add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type';}
#代理/logo资源请求
location /logo/ {proxy_pass http://localhost/dify/logo/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;
}
#解决跳转登录404(也可直接在dify页面修改跳转地址)
location /signin/ {proxy_pass http://localhost/dify/signin/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;
}