Path: API › 网站管理

`POST /site`

为指定网站部署自定义 SSL 证书（PEM 格式）。面板会验证证书和私钥的匹配性、证书链完整性，验证通过后写入配置并重载 Web 服务器。

## Request body

_Required._

- `action268.request_time` (string, required) — Unix 时间戳。
- `action268.request_token` (string, required) — 按 API 概览生成的签名。
- `action268.action` (string, required) — 具体操作名称。
  - one of `"SetSSL"`
- `action268.siteName` (string, required) — 网站域名
- `action268.key` (string, required) — 证书私钥（PEM 格式，含 `-----BEGIN PRIVATE KEY-----`）
- `action268.csr` (string, required) — 证书文件（PEM 格式，含 `-----BEGIN CERTIFICATE-----`）

## Example request

```text
{
  "request_time": "string",
  "request_token": "string",
  "action": "SetSSL",
  "siteName": "string",
  "key": "string",
  "csr": "string"
}
```

## Code samples

### cURL（填写面板地址与签名）

```curl
curl --request POST \
  --url "https://your-panel.example.com:8888/site" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "request_time=<Unix时间戳>" \
  --data-urlencode "request_token=<按 API 概览生成的签名>" \
  --data-urlencode "action=SetSSL" \
  --data-urlencode "siteName=<siteName>" \
  --data-urlencode "key=<key>" \
  --data-urlencode "csr=<csr>"
```

## Responses

### default

接口响应，业务状态见下方详细说明。

#### Example

```json
{
  "status": true,
  "msg": "证书已保存!"
}
```

- `action268.response.default.status` (boolean, optional) — `true` 表示部署成功
- `action268.response.default.msg` (string, optional) — `证书已保存!`


## SetSSL

为指定网站部署自定义 SSL 证书（PEM 格式）。面板会验证证书和私钥的匹配性、证书链完整性，验证通过后写入配置并重载 Web 服务器。

- **路由**：`POST /site`
- **action**：`SetSSL`

## 输入参数

| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| action | 是 | String | 固定值 `SetSSL` |
| siteName | 是 | String | 网站域名 |
| key | 是 | String | 证书私钥（PEM 格式，含 `-----BEGIN PRIVATE KEY-----`） |
| csr | 是 | String | 证书文件（PEM 格式，含 `-----BEGIN CERTIFICATE-----`） |

## 验证规则

- `key` 必须包含 `KEY`
- `csr` 必须包含 `CERTIFICATE`
- 证书必须是有效的 PEM 格式
- 私钥和证书必须互相对应匹配
- 证书链必须完整

验证失败时返回具体错误提示。

## 输出参数

| 参数名称 | 类型 | 描述 |
|----------|------|------|
| status | Boolean | `true` 表示部署成功 |
| msg | String | `证书已保存!` |

## 示例

### 生成自签名证书

```bash
openssl genrsa -out key.pem 2048
openssl req -new -x509 -key key.pem -out cert.pem -days 365 \
  -subj "/C=CN/ST=GD/L=SZ/O=Test/CN=testapi.bt.local"
```

### 请求

```
POST /site HTTP/1.1
Content-Type: application/x-www-form-urlencoded

action=SetSSL&siteName=testapi.bt.local&key=-----BEGIN PRIVATE KEY-----...&csr=-----BEGIN CERTIFICATE-----...
```

> `key` 和 `csr` 中换行符 `\n` 需保留。

### 响应

```json
{"status": true, "msg": "证书已保存!"}
```

## 相关接口

- [GetSSL](/api/site/getssl) — 查看证书信息
- [CloseSSLConf](/api/site/closesslconf) — 关闭 SSL
- [HttpToHttps](/api/site/closetohttps) — HTTP→HTTPS 跳转

