Path: 宝塔面板 API 参考 › Proxy 反向代理

`POST /mod/proxy/com/{action}/stype`

这个请求地址通过 action 区分具体功能。下方列出每个 action 的参数、约束和调用示例。

## Path parameters

- `opPostModProxyComActionStype.path.action` (string, required) — 具体操作名称，参见下方原始接口文档。

## Request body

_Required._

- `opPostModProxyComActionStype.request_time` (string, required) — Unix 时间戳；与接口密钥一起生成 request_token。
- `opPostModProxyComActionStype.request_token` (string, required) — 按 API 概览中的双重 MD5 签名算法生成。

## Example request

```text
{
  "request_time": "string",
  "request_token": "string"
}
```

## Code samples

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

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

## Responses

### default

响应因 action 而异，见下方各 action 的详细说明。


## batch_delete / batch_del_domain

批量删除反向代理站点或域名。

- **路由**：`POST /mod/proxy/com/{action}/stype`

---

## batch_delete — 批量删除站点

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_list | 是 | json | JSON 数组，每项含 `id` 和 `site_name`，如 `[{"id":1,"site_name":"a.com"}]` |
| remove_path/d | 否 | int | 是否同时删除网站目录，1 删除，0 保留（默认） |
| reload/d | 否 | int | 是否重载 Nginx，0 不重载（操作完成后自动重载一次） |

### 响应
```json
{
  "status": true,
  "msg": "批量删除站点成功！",
  "data": [{"site_name": "a.com", "status": true}]
}
```

---

## batch_del_domain — 批量删除域名

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| id | 是 | int | 站点 ID |
| site_name | 是 | string | 站点名称 |
| domains | 是 | string | 域名列表，换行分隔 |

### 响应
```json
{
  "status": true,
  "data": [{"name": "api.example.com", "status": true, "msg": "删除成功"}]
}
```


## save_config / get_config

获取和保存反向代理站点的 Nginx 配置（http_block / server_block）。

- **路由**：`POST /mod/proxy/com/{action}/stype`

---

## get_config — 获取配置

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |

### 输出参数
| 参数名称 | 类型 | 描述 |
|----------|------|------|
| data.site_conf | string | 完整 Nginx 配置文件内容 |
| data.http_block | string | http 块自定义配置 |
| data.server_block | string | server 块自定义配置 |
| data.ssl_conf | string | SSL 配置 |

---

## save_config — 保存配置

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| conf_type | 是 | string | 配置类型：`http_block` 或 `server_block` |
| body | 是 | string | 配置内容 |

### 响应
```json
{"code": 0, "status": true, "msg": "保存成功！"}
```


## add_domain / del_domain

## add_domain / del_domain / batch_del_domain

管理反向代理站点的域名绑定。

- **路由**：`POST /mod/proxy/com/{action}/stype`

## add_domain — 添加域名

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| id | 是 | int | 站点 ID |
| site_name | 是 | string | 站点名称 |
| domains | 是 | string | 域名，多个用换行符分隔，可带端口 `domain:8080` |

## del_domain — 删除单个域名

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| id | 是 | int | 站点 ID |
| site_name | 是 | string | 站点名称 |
| domain | 是 | string | 要删除的域名 |
| port | 是 | string | 域名对应端口 |

> **注意**：至少保留一个域名。


## batch_del_domain — 批量删除域名

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| id | 是 | int | 站点 ID |
| site_name | 是 | string | 站点名称 |
| domains | 是 | string | 域名列表，换行分隔 |

## 输出参数
| 参数名称 | 类型 | 描述 |
|----------|------|------|
| status | bool | 操作结果 |
| msg | string | 提示信息 |
| data | list | (add_domain 返回) 域名列表；(batch_del_domain 返回) 删除结果数组 |

## 示例

### add_domain 请求
```bash
curl -X POST "http://192.168.168.213:8888/mod/proxy/com/add_domain/stype" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "id=1&site_name=example.com&domains=www.example.com%0Aapi.example.com:8080&request_time=...&request_token=..."
```

### del_domain 请求
```bash
curl -X POST "http://192.168.168.213:8888/mod/proxy/com/del_domain/stype" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "id=1&site_name=example.com&domain=api.example.com&port=8080&request_time=...&request_token=..."
```


## add_ip_limit / del_ip_limit

管理反向代理站点的 IP 黑白名单。

- **路由**：`POST /mod/proxy/com/{action}/stype`

## add_ip_limit — 添加 IP 限制

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| ips | 是 | string | IP 列表，多个用换行符分隔。支持 CIDR 格式如 `10.0.0.0/8` |

> **说明**：IP 限制作用于指定 `proxy_path` 上。若未指定 `proxy_path`，则作用于全局。


## del_ip_limit — 删除 IP 限制

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| ip_type | 是 | string | 类型：`black` 或 `white` |
| ip | 是 | string | 要删除的 IP 地址 |

## 示例

### add_ip_limit 请求
```bash
curl -X POST ".../mod/proxy/com/add_ip_limit/stype" \
  -d "site_name=example.com&ips=192.168.1.100%0A10.0.0.0/8"
```

### del_ip_limit 请求
```bash
curl -X POST ".../mod/proxy/com/del_ip_limit/stype" \
  -d "site_name=example.com&ip_type=black&ip=192.168.1.100"
```

### 响应
```json
{"code": 0, "status": true, "msg": "设置成功！"}
```


## add_sub_filter / del_sub_filter

管理反向代理的内容替换（sub_filter）规则，用于在代理响应中替换文本。

- **路由**：`POST /mod/proxy/com/{action}/stype`

## add_sub_filter — 添加内容替换

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| proxy_path | 是 | string | 代理路径，如 `/` |
| oldstr | 是 | string | 被替换的字符串 |
| newstr | 是 | string | 替换后的字符串 |
| sub_type | 否 | string | 替换类型，由 `g`(全局), `i`(忽略大小写), `o`(只匹配一次), `r`(正则) 组合。注意 `g` 和 `o` 不能同时存在 |

## del_sub_filter — 删除内容替换

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| proxy_path | 是 | string | 代理路径 |
| oldstr | 是 | string | 被替换的字符串（需与添加时一致） |
| newstr | 是 | string | 替换后的字符串（需与添加时一致） |

## 示例

### add_sub_filter 请求
```bash
curl -X POST ".../mod/proxy/com/add_sub_filter/stype" \
  -d "site_name=example.com&proxy_path=/&oldstr=http://&newstr=https://&sub_type=ig"
```

### del_sub_filter 请求
```bash
curl -X POST ".../mod/proxy/com/del_sub_filter/stype" \
  -d "site_name=example.com&proxy_path=/&oldstr=http://&newstr=https://"
```

### 响应
```json
{"code": 0, "status": true, "msg": "设置成功！"}
```


## set_url_cache / set_url_gzip / set_url_custom_conf

## URL 级别配置

以下 API 用于对特定 `proxy_path` 设置独立的缓存、Gzip 和自定义 Nginx 配置。

- **路由**：`POST /mod/proxy/com/{action}/stype`

---

## set_url_cache — 设置 URL 级别缓存

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| proxy_path | 是 | string | 代理路径 |
| cache_status/d | 是 | int | 1 开启，0 关闭 |
| expires | 否 | string | 缓存过期时间，默认 `1d` |
| cache_suffix | 是 | string | 缓存的文件后缀，如 `css,js,jpg,jpeg,gif,png` |

### 响应
```json
{"code": 0, "status": true, "msg": "设置成功！"}
```

---

## set_url_gzip — 设置 URL 级别 Gzip

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| proxy_path | 是 | string | 代理路径 |
| gzip_status/d | 是 | int | 1 开启，0 关闭 |

### 响应
```json
{"code": 0, "status": true, "msg": "设置成功！"}
```

---

## set_url_custom_conf — 设置 URL 级别自定义配置

### 输入参数
| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| site_name | 是 | string | 站点名称 |
| proxy_path | 是 | string | 代理路径 |
| custom_conf | 是 | string | Nginx 自定义配置内容 |

### 响应
```json
{"code": 0, "status": true, "msg": "设置成功！"}
```

