当前位置:   article > 正文

Dify配置https协议_dify 地址打不开

dify 地址打不开

Dify配置https协议访问

我们再本地开发时服务启动后登录系统时无法登录,查看浏览器控制台发现访问后端接口均提示 401。这是由于前端和后的域名/网址不一致,导致前端和服务端跨域。

通过官方文档说明解决服务端与 web 客户端跨域,服务端必须为 https。

1、服务端配置https网关

由于部署dify的web、api端使用的nginx做的代理网关,因此我们只需对nginx进行配置https协议即可。在配置之前我们需要准备 server.pemserver.key 两个格式的证书文件。
进入 /dify-0.3.22/docker/nginx/conf.d 文件中,创建 cacerts 文件将 server.pemserver.key 放入该目录中。编辑 default.conf 文件:(这里我增加了logs日志的打印,可以忽略)

server {
	listen 443 ssl;
	server_name 域名;
	ssl on;
	ssl_certificate /etc/nginx/conf.d/cacerts/server.pem;
	ssl_certificate_key /etc/nginx/conf.d/cacerts/server.key;
	access_log /etc/nginx/conf.d/logs/access.log  main;
	error_log /etc/nginx/conf.d/logs/error.log  info;

    location /console/api {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location /api {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location /v1 {
      proxy_pass http://api:5001;
      include proxy.conf;
    }

    location / {
      proxy_pass http://web:3000;
      include proxy.conf;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

这里将原本的80端口改为443端口,增加了证书文件的配置。同步需要将docker容器映射的端口进行修改

2、修改服务端容器端口映射配置

进入/dify-0.3.22/docker目录下,编辑docker-compose.yaml文件,

  1. 修改映射端口,将80:80替换为443:443。例如:
  nginx:
    image: nginx:latest
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/proxy.conf:/etc/nginx/proxy.conf
      - ./nginx/conf.d:/etc/nginx/conf.d
    depends_on:
      - api
      - web
    ports:
      - "443:443"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  1. 修改跨域策略 (请勿应在生产)
WEB_API_CORS_ALLOW_ORIGINS: '*'
CONSOLE_CORS_ALLOW_ORIGINS: '*'
COOKIE_HTTPONLY: 'true'
COOKIE_SAMESITE: 'None'
COOKIE_SECURE: 'true'
  • 1
  • 2
  • 3
  • 4
  • 5

由于 SameSite=None 必须配合 Secure=true,因此服务端必须为 https 协议才能实现跨域访问

3、本地web服务配置服务端API

修改web跟目录下的.env文件,这里必须配置域名,不能配置IP

NEXT_PUBLIC_API_PREFIX=https://域名/console/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=https://域名/api
  • 1
  • 2

注意:配置域名的地方需填写你项目中实际的域名

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/155520
推荐阅读
相关标签
  

闽ICP备14008679号