[DOCS]: 本地部署之后,访问web,登录成功后,访问其他空间等其他页面,老是返回401,跳到登录页面 #270

Closed
opened 2026-02-16 05:19:40 -05:00 by yindo · 3 comments
Owner

Originally created by @liulongli001 on GitHub (Nov 13, 2025).

Type of Documentation Change

Error/Typo fix

Documentation Page URL or Path

No response

Current Content

本地部署之后,访问web,登录成功后,访问其他空间等其他页面,老是返回401,跳到登录页面

Suggested Changes

希望能够正常访问

Reason for Change

No response

Code of Conduct

  • I agree to follow Dify's documentation contribution guidelines
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.
Originally created by @liulongli001 on GitHub (Nov 13, 2025). ### Type of Documentation Change Error/Typo fix ### Documentation Page URL or Path _No response_ ### Current Content 本地部署之后,访问web,登录成功后,访问其他空间等其他页面,老是返回401,跳到登录页面 ### Suggested Changes 希望能够正常访问 ### Reason for Change _No response_ ### Code of Conduct - [x] I agree to follow Dify's documentation [contribution guidelines](https://github.com/langgenius/dify/blob/0277a37fcad5ad86aeb239485c27fffd5cd90043/CONTRIBUTING.md) - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields.
yindo added the documentation label 2026-02-16 05:19:40 -05:00
yindo closed this issue 2026-02-16 05:19:40 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 13, 2025):

Hi @liulongli001! I'm Dosu and I’m helping the dify-docs team.

本地部署 Dify 后登录成功但访问其他页面反复 401 跳转登录,常见原因是本地环境的 Cookie、CORS 或环境变量配置不正确。近期 Dify 已将认证 token 存储方式从 localStorage 改为 HTTP-only Cookie,导致本地开发时如果 Cookie 没有正确设置或被浏览器拦截,就会出现 401 问题。

排查和修复建议:

  1. 前端和后端都用 https(本地可用自签证书),否则浏览器可能拒绝带 Secure 标记的 Cookie,导致认证失败。参考
  2. COOKIE_DOMAIN 环境变量建议本地留空(不要设置为 localhost),否则 Cookie 可能无法被正确识别。
  3. 后端 CORS 配置要允许 credentials,并且 Access-Control-Allow-Origin 必须明确写前端地址(不能用 *)。
  4. 前后端不要用 localhost 不同端口(如 3000/5000),否则 Cookie 可能因 domain 或 SameSite 设置被浏览器拦截。
  5. 用浏览器开发者工具检查 Set-Cookie 响应和请求 Cookie,确认没有被 SameSite、Secure 或 domain 限制拦截。
  6. 检查 .env 或 docker-compose.yml 里的 SECRET_KEY、SESSION_SECRET_KEY 等环境变量,必须设置且一致,否则所有接口都会 401。参考
  7. 如果用 Redis 且启用 SSL,相关 REDIS_USE_SSL、REDIS_SSL_CERT_REQS 变量也要配置正确。

这些配置调整后,Cookie 能被正常设置和携带,401 问题即可解决。如需进一步排查,可关注近期关于 Cookie、认证和 401 错误的相关 issuePR

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 13, 2025): <!-- Greeting --> Hi @liulongli001! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify-docs team. <!-- Answer --> 本地部署 Dify 后登录成功但访问其他页面反复 401 跳转登录,常见原因是本地环境的 Cookie、CORS 或环境变量配置不正确。近期 Dify 已将认证 token 存储方式从 localStorage 改为 HTTP-only Cookie,导致本地开发时如果 Cookie 没有正确设置或被浏览器拦截,就会出现 401 问题。 排查和修复建议: 1. 前端和后端都用 https(本地可用自签证书),否则浏览器可能拒绝带 Secure 标记的 Cookie,导致认证失败。[参考](https://github.com/langgenius/dify/issues/27561) 2. COOKIE_DOMAIN 环境变量建议本地留空(不要设置为 localhost),否则 Cookie 可能无法被正确识别。 3. 后端 CORS 配置要允许 credentials,并且 Access-Control-Allow-Origin 必须明确写前端地址(不能用 *)。 4. 前后端不要用 localhost 不同端口(如 3000/5000),否则 Cookie 可能因 domain 或 SameSite 设置被浏览器拦截。 5. 用浏览器开发者工具检查 Set-Cookie 响应和请求 Cookie,确认没有被 SameSite、Secure 或 domain 限制拦截。 6. 检查 .env 或 docker-compose.yml 里的 SECRET_KEY、SESSION_SECRET_KEY 等环境变量,必须设置且一致,否则所有接口都会 401。[参考](https://github.com/langgenius/dify/issues/26982) 7. 如果用 Redis 且启用 SSL,相关 REDIS_USE_SSL、REDIS_SSL_CERT_REQS 变量也要配置正确。 这些配置调整后,Cookie 能被正常设置和携带,401 问题即可解决。如需进一步排查,可关注近期关于 Cookie、认证和 401 错误的[相关 issue](https://github.com/langgenius/dify/issues/27561) 和 [PR](https://github.com/langgenius/dify/pull/24365)。 <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7085fd0d-e5a0-4b45-acff-1fcce1be1b3d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-docs/issues/521)
Author
Owner

@kittyton commented on GitHub (Nov 25, 2025):

请问您这个问题解决了吗?怎么解决的

@kittyton commented on GitHub (Nov 25, 2025): 请问您这个问题解决了吗?怎么解决的
Author
Owner

@dosubot[bot] commented on GitHub (Nov 25, 2025):

@crazywoola, the user kittyton has indicated that the issue is still unresolved and is asking how to solve it. Could you please assist them with the 401 error related to local environment cookie and CORS configuration?

@dosubot[bot] commented on GitHub (Nov 25, 2025): @crazywoola, the user kittyton has indicated that the issue is still unresolved and is asking how to solve it. Could you please assist them with the 401 error related to local environment cookie and CORS configuration?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs#270