[GH-ISSUE #1111] Nginx UI 2.1.0 版本代理路径有后缀登录异常 #7724

Closed
opened 2026-03-12 22:23:32 +03:00 by kerem · 3 comments
Owner

Originally created by @davidche1116 on GitHub (Jun 4, 2025).
Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/1111

Describe the bug
在 Nginx UI 2.1.0 版本中,通过 Nginx 反向代理添加路径后缀(如 /nginx/)后,登录功能报“服务器异常”,而直接访问后端端口(9000)或回退至 2.0.2 版本均正常。

To Reproduce
Steps to reproduce the behavior:

  1. 安装 Nginx UI 2.1.0,监听 127.0.0.1:9000。
  2. 配置 Nginx 代理:
location /nginx/ {
    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_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_pass http://127.0.0.1:9000/;  # 注意末尾斜杠
}
  1. 通过 http://your-domain.com/nginx/ 打开 Nginx UI
  2. 输入账号密码点击登录,页面返回“服务器异常”错误。

Expected behavior​
通过代理路径 /nginx/ 应能正常登录,功能与直接访问 127.0.0.1:9000 或 2.0.2 版本一致
理路径下的静态资源(JS/CSS)和 API 请求应正确加载,无会话丢失问题
或者在docker部署的时候,增加配置文件。支持/nginx前缀配置(域名和证书都需要节省,不得已采用这种后缀域名)

Info (please complete the following information):

  • Server OS: Ubuntu 22.04
  • Server Arch:x86_64
  • Nginx UI Version:2.1.0
  • Your Browser: Chrome

Additional context
​​问题根源分析​​:
1.​​Cookie 路径不匹配​​
​​2.静态资源路径错误​​:
前端资源(如 JS/CSS)可能使用绝对路径(如 /static/xxx.js),代理后路径变为 /nginx/static/xxx.js,但资源实际位于后端根路径,导致 404 错误。
3.​​API 请求路径错误​​:
登录请求可能发送至 /api/login,但代理后路径应为 /nginx/api/login,后端路由不匹配。
​​临时解决方案​​:
​​回退版本​​:使用 2.0.2 版本可正常工作。

​​修复建议​​:
1.​​动态路径适配​​:
后端应根据 X-Forwarded-Prefix 头自动调整 Cookie 路径和 API 路由前缀(需 Nginx 配置 proxy_set_header X-Forwarded-Prefix /nginx/;)。
​​2.前端资源路径兼容​​
3.新增支持使用WEB_CONTEXT='/nginx'之类的docker环境变量配置

Originally created by @davidche1116 on GitHub (Jun 4, 2025). Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/1111 **Describe the bug** 在 Nginx UI 2.1.0 版本中,通过 Nginx 反向代理添加路径后缀(如 /nginx/)后,登录功能报“服务器异常”,而直接访问后端端口(9000)或回退至 2.0.2 版本均正常。 **To Reproduce** Steps to reproduce the behavior: 1. 安装 Nginx UI 2.1.0,监听 127.0.0.1:9000。 2. 配置 Nginx 代理: ``` location /nginx/ { 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_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_pass http://127.0.0.1:9000/; # 注意末尾斜杠 } ``` 4. 通过 http://your-domain.com/nginx/ 打开 Nginx UI 5. 输入账号密码点击登录,页面返回“服务器异常”错误。 **Expected behavior​** 通过代理路径 /nginx/ 应能正常登录,功能与直接访问 127.0.0.1:9000 或 2.0.2 版本一致 理路径下的静态资源(JS/CSS)和 API 请求应正确加载,无会话丢失问题 或者在docker部署的时候,增加配置文件。支持/nginx前缀配置(域名和证书都需要节省,不得已采用这种后缀域名) **Info (please complete the following information):** - Server OS: Ubuntu 22.04 - Server Arch:x86_64 - Nginx UI Version:2.1.0 - Your Browser: Chrome **Additional context** ​​问题根源分析​​: 1.​​Cookie 路径不匹配​​ ​​2.静态资源路径错误​​: 前端资源(如 JS/CSS)可能使用绝对路径(如 /static/xxx.js),代理后路径变为 /nginx/static/xxx.js,但资源实际位于后端根路径,导致 404 错误。 3.​​API 请求路径错误​​: 登录请求可能发送至 /api/login,但代理后路径应为 /nginx/api/login,后端路由不匹配。 ​​临时解决方案​​: ​​回退版本​​:使用 2.0.2 版本可正常工作。 ​​修复建议​​: 1.​​动态路径适配​​: 后端应根据 X-Forwarded-Prefix 头自动调整 Cookie 路径和 API 路由前缀(需 Nginx 配置 proxy_set_header X-Forwarded-Prefix /nginx/;)。 ​​2.前端资源路径兼容​​ 3.新增支持使用WEB_CONTEXT='/nginx'之类的docker环境变量配置
kerem 2026-03-12 22:23:32 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@0xJacky commented on GitHub (Jun 4, 2025):

刚刚,已经修复

<!-- gh-comment-id:2938058560 --> @0xJacky commented on GitHub (Jun 4, 2025): 刚刚,已经修复
Author
Owner

@0xJacky commented on GitHub (Jun 4, 2025):

稍后将会发布 v2.1.1

<!-- gh-comment-id:2938061844 --> @0xJacky commented on GitHub (Jun 4, 2025): 稍后将会发布 v2.1.1
Author
Owner

@davidche1116 commented on GitHub (Jun 4, 2025):

看到了。真快

<!-- gh-comment-id:2938064569 --> @davidche1116 commented on GitHub (Jun 4, 2025): 看到了。真快
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-ui#7724
No description provided.