Development Environment Configuration #3

Closed
opened 2026-02-21 17:25:29 -05:00 by yindo · 18 comments
Owner

Originally created by @skywalker512 on GitHub (May 14, 2023).

我按照你们的指南进行配置,但是遇到了一些问题

  1. 你们的指南中没有提到如何配置 web 的 .env.local 文件
# web/.env.local
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
NEXT_PUBLIC_EDITION=SELF_HOSTED
NEXT_PUBLIC_API_PREFIX=http://127.0.0.1:5001/console/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=http://127.0.0.1:5001/api
  1. docker/volumes/db/scripts 似乎有权限问题
    ls: can't open '/docker-entrypoint-initdb.d/': Permission denied

  2. 没有告诉用户需要在 http://localhost:3000/install 进行管理员配置

  3. CHECK_UPDATE_URL 需要访问你们的在线服务,在中国访问有些问题

Originally created by @skywalker512 on GitHub (May 14, 2023). 我按照你们的指南进行配置,但是遇到了一些问题 1. 你们的指南中没有提到如何配置 web 的 .env.local 文件 ``` # web/.env.local NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT NEXT_PUBLIC_EDITION=SELF_HOSTED NEXT_PUBLIC_API_PREFIX=http://127.0.0.1:5001/console/api NEXT_PUBLIC_PUBLIC_API_PREFIX=http://127.0.0.1:5001/api ``` 2. docker/volumes/db/scripts 似乎有权限问题 ls: can't open '/docker-entrypoint-initdb.d/': Permission denied 3. 没有告诉用户需要在 http://localhost:3000/install 进行管理员配置 4. CHECK_UPDATE_URL 需要访问你们的在线服务,在中国访问有些问题
yindo added the 🐞 bug📚 documentation labels 2026-02-21 17:25:29 -05:00
yindo closed this issue 2026-02-21 17:25:29 -05:00
Author
Owner

@takatost commented on GitHub (May 14, 2023):

  1. 这个问题确实是权限问题,我们优先修一下这个
@takatost commented on GitHub (May 14, 2023): 2. 这个问题确实是权限问题,我们优先修一下这个
Author
Owner

@takatost commented on GitHub (May 15, 2023):

@skywalker512 问题 2 fixed
重新部署前需要拉一下服务端最新镜像
docker pull langgenius/dify-api:latest

@takatost commented on GitHub (May 15, 2023): @skywalker512 问题 2 fixed 重新部署前需要拉一下服务端最新镜像 docker pull langgenius/dify-api:latest
Author
Owner

@iamjoel commented on GitHub (May 15, 2023):

关于 1

  1. NEXT_PUBLIC_DEPLOY_ENV: 开发环境。本地跑用设值为 DEVELOPMENT,生产环境设 PRODUCTION。
  2. NEXT_PUBLIC_EDITION: 写死值为 SELF_HOSTED。
  3. NEXT_PUBLIC_API_PREFIX:后台的接口前缀。
  4. NEXT_PUBLIC_PUBLIC_API_PREFIX:分享出去的 webapp 的接口前缀。
@iamjoel commented on GitHub (May 15, 2023): 关于 1 1. NEXT_PUBLIC_DEPLOY_ENV: 开发环境。本地跑用设值为 DEVELOPMENT,生产环境设 PRODUCTION。 2. NEXT_PUBLIC_EDITION: 写死值为 SELF_HOSTED。 3. NEXT_PUBLIC_API_PREFIX:后台的接口前缀。 4. NEXT_PUBLIC_PUBLIC_API_PREFIX:分享出去的 webapp 的接口前缀。
Author
Owner

@muxuan1978 commented on GitHub (May 15, 2023):

部署成功了,可以配置保存,但是登录成功后先跳到/apps页面,过一会还是会跳转到登录页面signin

@muxuan1978 commented on GitHub (May 15, 2023): 部署成功了,可以配置保存,但是登录成功后先跳到/apps页面,过一会还是会跳转到登录页面signin
Author
Owner

@takatost commented on GitHub (May 15, 2023):

部署成功了,可以配置保存,但是登录成功后先跳到/apps页面,过一会还是会跳转到登录页面signin

和 cookie 策略可能有关系,有修改过什么配置或者端口、域名吗?

docker-compose.yml 中有这些配置和跨域策略、cookie 策略相关,可以尝试修改

      # Specifies the allowed origins for cross-origin requests to the Web API
      WEB_API_CORS_ALLOW_ORIGINS: http://localhost,*
      # Specifies the allowed origins for cross-origin requests to the console API
      CONSOLE_CORS_ALLOW_ORIGINS: http://localhost,*
      # CSRF Cookie settings
      # Controls whether a cookie is sent with cross-site requests,
      # providing some protection against cross-site request forgery attacks
      COOKIE_HTTPONLY: 'true'
      COOKIE_SAMESITE: 'None'
      COOKIE_SECURE: 'true'
@takatost commented on GitHub (May 15, 2023): > 部署成功了,可以配置保存,但是登录成功后先跳到/apps页面,过一会还是会跳转到登录页面signin 和 cookie 策略可能有关系,有修改过什么配置或者端口、域名吗? docker-compose.yml 中有这些配置和跨域策略、cookie 策略相关,可以尝试修改 ``` # Specifies the allowed origins for cross-origin requests to the Web API WEB_API_CORS_ALLOW_ORIGINS: http://localhost,* # Specifies the allowed origins for cross-origin requests to the console API CONSOLE_CORS_ALLOW_ORIGINS: http://localhost,* # CSRF Cookie settings # Controls whether a cookie is sent with cross-site requests, # providing some protection against cross-site request forgery attacks COOKIE_HTTPONLY: 'true' COOKIE_SAMESITE: 'None' COOKIE_SECURE: 'true' ```
Author
Owner

@jiangpengwz commented on GitHub (May 15, 2023):

自定义域名,doker-compse.yml里所有localhost都已经修改为自定义域名。install和登陆时,通过控制台查看网络调用api,发现
image
也是bug么?

额外信息,修改了docker-compose.yaml中,nginx的外部端口为81,然后通过宿主机的nginx做的域名转发到localhost:81。

@jiangpengwz commented on GitHub (May 15, 2023): > 自定义域名,doker-compse.yml里所有localhost都已经修改为自定义域名。install和登陆时,通过控制台查看网络调用api,发现 ![image](https://github.com/langgenius/dify/assets/25921220/10516add-c620-44a9-b568-2c5f921d6bf9) 也是bug么? 额外信息,修改了docker-compose.yaml中,nginx的外部端口为81,然后通过宿主机的nginx做的域名转发到localhost:81。
Author
Owner

@takatost commented on GitHub (May 15, 2023):

自定义域名,doker-compse.yml里所有localhost都已经修改为自定义域名。install和登陆时,通过控制台查看网络调用api,发现 image 也是bug么?

额外信息,修改了docker-compose.yaml中,nginx的外部端口为81,然后通过宿主机的nginx做的域名转发到localhost:81。

Set-Cookie 处有个感叹号,应该和这个相关,可以看下是什么 warning 信息

@takatost commented on GitHub (May 15, 2023): > > > > 自定义域名,doker-compse.yml里所有localhost都已经修改为自定义域名。install和登陆时,通过控制台查看网络调用api,发现 ![image](https://user-images.githubusercontent.com/25921220/238280188-10516add-c620-44a9-b568-2c5f921d6bf9.png) 也是bug么? > > 额外信息,修改了docker-compose.yaml中,nginx的外部端口为81,然后通过宿主机的nginx做的域名转发到localhost:81。 Set-Cookie 处有个感叹号,应该和这个相关,可以看下是什么 warning 信息
Author
Owner

@jiangpengwz commented on GitHub (May 15, 2023):

image
破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。

@jiangpengwz commented on GitHub (May 15, 2023): > ![image](https://github.com/langgenius/dify/assets/25921220/a3c94ada-41e2-49a1-a691-1789385d0fd2) 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。
Author
Owner

@MartialBE commented on GitHub (May 15, 2023):

image 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。

http 这样设置:

COOKIE_SAMESITE: 'Lax'
COOKIE_SECURE: 'false'

SameSite 为None时 Secure必须设置。

@MartialBE commented on GitHub (May 15, 2023): > > > > ![image](https://user-images.githubusercontent.com/25921220/238282421-a3c94ada-41e2-49a1-a691-1789385d0fd2.png) 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。 http 这样设置: ``` COOKIE_SAMESITE: 'Lax' COOKIE_SECURE: 'false' ``` SameSite 为None时 Secure必须设置。
Author
Owner

@takatost commented on GitHub (May 15, 2023):

image 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。

可能需要重启下 nginx:

docker restart <nginx container id>
@takatost commented on GitHub (May 15, 2023): > > > > ![image](https://user-images.githubusercontent.com/25921220/238282421-a3c94ada-41e2-49a1-a691-1789385d0fd2.png) 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。 可能需要重启下 nginx: ``` docker restart <nginx container id> ```
Author
Owner

@takatost commented on GitHub (May 15, 2023):

image 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。

http 这样设置:

COOKIE_SAMESITE: 'Lax'
COOKIE_SECURE: 'false'

SameSite 为None时 Secure必须设置。

默认配置可能太严格了,我改宽松点看看

@takatost commented on GitHub (May 15, 2023): > > > > > > > > > ![image](https://user-images.githubusercontent.com/25921220/238282421-a3c94ada-41e2-49a1-a691-1789385d0fd2.png) 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。 > > http 这样设置: > > ``` > COOKIE_SAMESITE: 'Lax' > COOKIE_SECURE: 'false' > ``` > > SameSite 为None时 Secure必须设置。 默认配置可能太严格了,我改宽松点看看
Author
Owner

@muxuan1978 commented on GitHub (May 15, 2023):

改了上面说的Cookie参数后可以了

@muxuan1978 commented on GitHub (May 15, 2023): > 改了上面说的Cookie参数后可以了
Author
Owner

@takatost commented on GitHub (May 15, 2023):

image 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。

可能需要重启下 nginx:

docker restart <nginx container id>

#23 改成了相对宽松的默认策略。

  • 默认策略

适用于本地调试用,支持 HTTP/HTTPS 协议,但需要保证前端页面和接口同域。

WEB_API_CORS_ALLOW_ORIGINS: '*'
CONSOLE_CORS_ALLOW_ORIGINS: '*'
COOKIE_HTTPONLY: 'true'
COOKIE_SAMESITE: 'Lax'
COOKIE_SECURE: 'false'
  • 跨域策略(请勿应在生产)

由于 SameSite=None 必须配合 Secure=true,因此服务端必须为 https 协议才能实现跨域访问,可以用在服务端在远程并且提供 https 协议支持,或者本地单独启动服务端和前端项目(localhost,但不同端口,实测可用,虽然提示 warning)。

WEB_API_CORS_ALLOW_ORIGINS: 'https://your-domain-for-web-app'
CONSOLE_CORS_ALLOW_ORIGINS: 'https://your-domain-for-console'
COOKIE_HTTPONLY: 'true'
COOKIE_SAMESITE: 'None'
COOKIE_SECURE: 'true'
  • 生产策略

由于部分第三方集成需要支持回调并带着 cookie 信息,因此不能使用最高的 Strict 策略,因此需要严格限制 CORS 域名,以及设置 cookie 策略为 SameSite=Lax Secure=true。

WEB_API_CORS_ALLOW_ORIGINS: 'https://your-domain-for-web-app'
CONSOLE_CORS_ALLOW_ORIGINS: 'https://your-domain-for-console'
COOKIE_HTTPONLY: 'true'
COOKIE_SAMESITE: 'Lax'
COOKIE_SECURE: 'true'

另外,如果切换域名了,请将 docker-compose.yml 中所有的以下配置项改为新的域名:

  • CONSOLE_URL:控制台域名
  • API_URL:Service API 域名
  • APP_URL:Web APP 域名
@takatost commented on GitHub (May 15, 2023): > > > > > > > > > ![image](https://user-images.githubusercontent.com/25921220/238282421-a3c94ada-41e2-49a1-a691-1789385d0fd2.png) 破案了,Secure是只能用在https上的。我吧COOKIE_SECURE 改成false就过了,但api502了。。。。 > > 可能需要重启下 nginx: > > ``` > docker restart <nginx container id> > ``` #23 改成了相对宽松的默认策略。 - 默认策略 适用于本地调试用,支持 HTTP/HTTPS 协议,但需要保证前端页面和接口同域。 ``` WEB_API_CORS_ALLOW_ORIGINS: '*' CONSOLE_CORS_ALLOW_ORIGINS: '*' COOKIE_HTTPONLY: 'true' COOKIE_SAMESITE: 'Lax' COOKIE_SECURE: 'false' ``` - 跨域策略(请勿应在生产) 由于 SameSite=None 必须配合 Secure=true,因此服务端必须为 `https` 协议才能实现跨域访问,可以用在服务端在远程并且提供 `https` 协议支持,或者本地单独启动服务端和前端项目(localhost,但不同端口,实测可用,虽然提示 warning)。 ``` WEB_API_CORS_ALLOW_ORIGINS: 'https://your-domain-for-web-app' CONSOLE_CORS_ALLOW_ORIGINS: 'https://your-domain-for-console' COOKIE_HTTPONLY: 'true' COOKIE_SAMESITE: 'None' COOKIE_SECURE: 'true' ``` - 生产策略 由于部分第三方集成需要支持回调并带着 cookie 信息,因此不能使用最高的 Strict 策略,因此需要严格限制 CORS 域名,以及设置 cookie 策略为 SameSite=Lax Secure=true。 ``` WEB_API_CORS_ALLOW_ORIGINS: 'https://your-domain-for-web-app' CONSOLE_CORS_ALLOW_ORIGINS: 'https://your-domain-for-console' COOKIE_HTTPONLY: 'true' COOKIE_SAMESITE: 'Lax' COOKIE_SECURE: 'true' ``` 另外,如果切换域名了,请将 docker-compose.yml 中所有的以下配置项改为新的域名: - CONSOLE_URL:控制台域名 - API_URL:Service API 域名 - APP_URL:Web APP 域名
Author
Owner

@wangboak commented on GitHub (May 16, 2023):

#在 dify目录下,下载 docker-compose.yaml
docker-compose up -d

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/host_mnt/Users/wangbo/soft/docker_app/dify/nginx/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /host_mnt/Users/wangbo/soft/docker_app/dify/nginx/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/9), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

nginx 一直启动不起来,有知道是什么原因吗?

@wangboak commented on GitHub (May 16, 2023): #在 dify目录下,下载 docker-compose.yaml docker-compose up -d Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/host_mnt/Users/wangbo/soft/docker_app/dify/nginx/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /host_mnt/Users/wangbo/soft/docker_app/dify/nginx/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/9), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type nginx 一直启动不起来,有知道是什么原因吗?
Author
Owner

@takatost commented on GitHub (May 16, 2023):

看起来是找不到文件,是否为 docker in docker 模式?没有把 host 目录挂载到 docker 对应目录?

@takatost commented on GitHub (May 16, 2023): 看起来是找不到文件,是否为 docker in docker 模式?没有把 host 目录挂载到 docker 对应目录?
Author
Owner

@wangboak commented on GitHub (May 16, 2023):

看起来是找不到文件,是否为 docker in docker 模式?没有把 host 目录挂载到 docker 对应目录?

已经解决了~ 我是直接下载了 docker-compose.yaml 这个文件,并 运行 docker-compose up -d 命令。
并没有git clone 整个项目,并在docker目录下执行此命令。
报错原因是 nginx运行所需的config文件不存在。

@wangboak commented on GitHub (May 16, 2023): > 看起来是找不到文件,是否为 docker in docker 模式?没有把 host 目录挂载到 docker 对应目录? 已经解决了~ 我是直接下载了 docker-compose.yaml 这个文件,并 运行 docker-compose up -d 命令。 并没有git clone 整个项目,并在docker目录下执行此命令。 报错原因是 nginx运行所需的config文件不存在。
Author
Owner

@renguowen commented on GitHub (May 16, 2023):

有遇到这个问题的吗,docker-compose up -d时报错ERROR: manifest for semitechnologies/weaviate:1.18.4 not found
手动拉取docker pull semitechnologies/weaviate:1.18.4也不行还是报错Error response from daemon: manifest for semitechnologies/weaviate:1.18.4 not found

@renguowen commented on GitHub (May 16, 2023): 有遇到这个问题的吗,docker-compose up -d时报错ERROR: manifest for semitechnologies/weaviate:1.18.4 not found 手动拉取docker pull semitechnologies/weaviate:1.18.4也不行还是报错Error response from daemon: manifest for semitechnologies/weaviate:1.18.4 not found
Author
Owner

@takatost commented on GitHub (May 16, 2023):

https://hub.docker.com/layers/semitechnologies/weaviate/1.18.4/images/sha256-ddad8839318b616eed4b594a55886a5166560c6ac77082f22242436a2226cde6?context=explore

镜像是存在的,可能使用的 dockerhub 镜像的问题

@takatost commented on GitHub (May 16, 2023): > https://hub.docker.com/layers/semitechnologies/weaviate/1.18.4/images/sha256-ddad8839318b616eed4b594a55886a5166560c6ac77082f22242436a2226cde6?context=explore 镜像是存在的,可能使用的 dockerhub 镜像的问题
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#3