## 1Panel 版本 v2.1.10(最新稳定版,2026-04-23) ## 问题类型 Bug: type="proxy" 网站创建 API 返回 500 内部错误 ## 问题描述 通过 REST API 创建 type="proxy" 类型的网站时,无论如何组合请求参数,都返回 **500 Internal Server Error**,响应体为空。 ## 复现步骤 ### API 端点 POST http://10.0.0.6:18866/api/v2/websites ### 请求头 1Panel-Token: <md5("1panel" + API_KEY + timestamp)> 1Panel-Timestamp: <unix_timestamp> Content-Type: application/json Accept: application/json ### 请求体(尝试了多种组合) **尝试 1: type="proxy" + appType 空** ```json { "primaryDomain": "test.com", "type": "proxy", "alias": "test", "remark": "", "appType": "", "appInstallId": 0, "webSiteGroupId": 5, "otherDomains": "", "proxy": "http://127.0.0.1:8080", "proxyType": "", "ftpUser": "", "ftpPassword": "" } ``` 结果: 400 - AppType validation failed ('oneof' tag 要求 non-empty) **尝试 2: type="proxy" + appType="new"** 结果: 500 - 响应体为空 **尝试 3: type="proxy" + appType="installed" + appInstallId=0** 结果: 500 - 响应体为空 **尝试 4: type 换为 "deployment" + appType="new" + appDetailId=4053** 结果: 500 - 响应体为空 ## 根因分析 通过阅读 1Panel 源码(dev 分支),发现 backend/app/service/website.go 第 274 行附近的 CreateWebsite 函数中: ```go switch create.Type { case constant.Deployment: // 处理代码... case constant.Runtime: // 处理代码... case constant.Node: // 处理代码... case constant.Java: // 处理代码... case constant.App: // 处理代码... case constant.Static: // 处理代码... // ❌ constant.Proxy 没有 case!会落入 default default: // ❌ 也没有处理 Proxy 类型 } ``` 当 type="proxy" 时,代码落入 default 分支,调用 configDefaultNginx(create, &website, appInstall)。对于 Proxy 类型,website.Proxy 是空字符串(因为没有任何 case 设置它),导致 createProxyFile 生成的 nginx 配置中 proxy_pass 为空。nginx 配置检查失败后,1Panel 回滚整个事务,返回 500 错误。 ## 前端代码证据 frontend/src/views/website/website/create/index.vue 中,对于 type="proxy" 类型,前端只设置了: ```javascript website.proxy = that.proxyAddress; ``` 但后端的 CreateWebsite switch 语句中没有对应的 case,所以 create.Proxy 值无法被正确传递到处理逻辑中。 ## 相关日志输出 无(500 错误响应体为空,无法获取更多调试信息) ## 期望的正常行为 能够通过 API 成功创建一个 type="proxy" 的网站,参数示例: ```json { "primaryDomain": "example.com", "type": "proxy", "alias": "example", "remark": "反向代理测试", "appType": "", "appInstallId": 0, "webSiteGroupId": 5, "otherDomains": "", "proxy": "http://127.0.0.1:8080", "proxyType": "", "ftpUser": "", "ftpPassword": "" } ``` ## 可能的修复方案 在 backend/app/service/website.go 的 CreateWebsite switch 中添加 constant.Proxy case: ```go case constant.Proxy: if create.proxy == "" { return nil, errors.New("proxy address is required") } website.Type = constant.Proxy website.Proxy = create.proxy if err := createWebsiteFolder(websitePath, website); err != nil { return nil, err } ``` ## 环境信息 - 1Panel 版本: v2.1.10 - 操作系统: debian (容器环境) - OpenResty: 1.21.4.3 - API Key: 已配置(可复现)
Activity