Dify API调用(嵌入Web)需要https


调用不显示,问Claude, 提示是http和https混合不被认可的问题。

后来尝试用命令行解决,不成功,因为部署dify用的是docker,稍微麻烦一些。而且如果不用宝塔,需要先绑定域名,再解决域名的SSL问题,是两个大步骤。走了个捷径用反代解决问题。

步骤:

一,创建静态调用域名的网站,反代127.0.0.1:8088($host)

二,利用面板为域名申请SSL

三,配置文件修改优化:

优化后的反向代理配置

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;
proxy_set_header X-Forwarded-Host $server_name;

WebSocket支持

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

性能优化关键配置

proxy_connect_timeout 10s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;

缓冲优化

proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 8 8k;
proxy_busy_buffers_size 16k;

禁用不必要的缓冲

proxy_request_buffering off;

HTTP版本

proxy_http_version 1.1;

文件上传

client_max_body_size 50M;

启用gzip压缩

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;

静态资源缓存

location ~* .(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
proxy_pass http://127.0.0.1:8088;
proxy_cache_valid 200 1h;
expires 1h;
add_header Cache-Control "public, immutable";
}

四,命令行修改dify目录的环境文件 .env

HTTPS域名配置

CONSOLE_API_URL=https://dify.abc.com
CONSOLE_WEB_URL=https://dify.abc.com
SERVICE_API_URL=https://dify.abc.com
APP_API_URL=https://dify.abc.com
APP_WEB_URL=https://dify.abc.com
FILES_URL=https://dify.abc.com

跨域和安全配置

WEB_API_CORS_ALLOW_ORIGINS=https://dify.abc.com,https://abc.com
CONSOLE_CORS_ALLOW_ORIGINS=https://dify.abc.com,https://abc.com
COOKIE_HTTPONLY=true
COOKIE_SAMESITE=None
COOKIE_SECURE=true

五,重新启动dify

docker-compose down
docker-compose up -d

还遇到了Dify Web嵌入时候按钮位置固定(点击按钮后弹窗位置固定)的问题,看来还有很多需要完善的地方。用作生产级的,应该更加灵活、完备和强大。


© 2026 Qie Lei (郄磊). All rights reserved.
This repository is for archival and proof of authorship only.
No part of this work may be reproduced, distributed, or used in any form without explicit permission from the author.
Github is used for original time verification
Github 用于原创时间保护认证

Published by , in 创业. Leave a reply

Leave a Reply

Your email address will not be published. Required fields are marked *