> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# http_* 服务器设置

> http_* 自动生成分组中的 ClickHouse 服务器设置。

这些设置用于配置 ClickHouse 服务器，并根据 ClickHouse 源代码自动生成。

## http\_allow\_path\_requests

类型

Bool

默认值

1

无需重启即可更改

No

允许 HTTP 接口将路径式请求 (例如 `/my_db/my_table.csv`) 路由至查询处理器。

此标志仅控制路由决策，该决策在对请求进行身份验证之前作出，因此不能依赖于用户级设置。路由后，用户级设置 [`http_allow_database_as_path`](https://clickhouse.com/docs/zh/reference/settings/session-settings#http_allow_database_as_path)、[`http_allow_table_as_file`](https://clickhouse.com/docs/zh/reference/settings/session-settings#http_allow_table_as_file) 和 [`http_allow_filters_as_path`](https://clickhouse.com/docs/zh/reference/settings/session-settings#http_allow_filters_as_path) 决定是否为已通过身份验证的用户实际解析路由后的路径。关闭此标志时，未知路径会返回普通的 `404`。

默认启用。将其设为 `0` 可恢复之前的行为：凡是未配置处理器的路径，一律返回 `404`。

**示例**

```xml theme={null}
<http_allow_path_requests>0</http_allow_path_requests>
```

## http\_handlers

允许使用自定义 HTTP 处理器。
要添加新的 HTTP 处理器，只需新增一条 `<rule>`。
规则会按定义顺序从上到下进行检查，
第一个匹配的规则将运行对应的处理器。

以下配置项可通过子标签进行配置：

| Sub-tags | Definition |
| - | - |
| `url` | 要匹配请求 URL，可以使用 'regex:' 前缀启用正则匹配 (可选) |
| `methods` | 要匹配请求方法，可以使用逗号分隔多个方法 (可选) |
| `headers` | 要匹配请求头，需要匹配每个子元素 (子元素名称即请求头名称) ，可以使用 'regex:' 前缀启用正则匹配 (可选) |
| `handler` | 请求处理器 |
| `empty_query_string` | 检查 URL 中是否不存在查询字符串 |

`handler` 包含以下配置项，这些也可通过子标签进行配置：

| Sub-tags | Definition |
| - | - |
| `url` | 重定向目标位置 |
| `type` | 支持的类型：static、dynamic\_query\_handler、predefined\_query\_handler、redirect |
| `status` | 与 static 类型一起使用，表示响应状态码 |
| `query_param_name` | 与 dynamic\_query\_handler 类型一起使用，提取并执行 HTTP 请求 params 中与 `<query_param_name>` 对应的值 |
| `query` | 与 predefined\_query\_handler 类型一起使用，在调用处理器时执行查询 |
| `content_type` | 与 static 类型一起使用，表示响应的 content-type |
| `response_content` | 与 static 类型一起使用，表示发送给客户端的响应内容；使用前缀 'file://' 或 'config://' 时，会从文件或配置中查找内容并发送给客户端 |

除了规则列表外，还可以指定 `<defaults/>`，表示启用所有默认处理器。

示例：

```xml theme={null}
<http_handlers>
    <rule>
        <url>/</url>
        <methods>POST,GET</methods>
        <headers><pragma>no-cache</pragma></headers>
        <handler>
            <type>dynamic_query_handler</type>
            <query_param_name>query</query_param_name>
        </handler>
    </rule>

    <rule>
        <url>/predefined_query</url>
        <methods>POST,GET</methods>
        <handler>
            <type>predefined_query_handler</type>
            <query>SELECT * FROM system.settings</query>
        </handler>
    </rule>

    <rule>
        <handler>
            <type>static</type>
            <status>200</status>
            <content_type>text/plain; charset=UTF-8</content_type>
            <response_content>config://http_server_default_response</response_content>
        </handler>
    </rule>
</http_handlers>
```

## http\_options\_response

用于在 `OPTIONS` HTTP 请求的响应中添加请求头。
`OPTIONS` 方法用于发起 CORS 预检请求。

更多信息，请参见 [OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS)。

示例：

```xml theme={null}
<http_options_response>
     <header>
            <name>Access-Control-Allow-Origin</name>
            <value>*</value>
     </header>
     <header>
          <name>Access-Control-Allow-Headers</name>
          <value>origin, x-requested-with, x-clickhouse-format, x-clickhouse-user, x-clickhouse-key, Authorization</value>
     </header>
     <header>
          <name>Access-Control-Allow-Methods</name>
          <value>POST, GET, OPTIONS</value>
     </header>
     <header>
          <name>Access-Control-Max-Age</name>
          <value>86400</value>
     </header>
</http_options_response>
```

## http\_server\_default\_response

访问 ClickHouse HTTP(s) 服务器时默认显示的页面。
默认值为 "Ok." (末尾带有一个换行符) 。

* **默认值：** `"Ok.\n"`

**示例**

访问 `http://localhost: http_port` 时，将打开 `https://tabix.io/`。

```xml theme={null}
<http_server_default_response>
  <![CDATA[<html ng-app="SMI2"><head><base href="http://ui.tabix.io/"></head><body><div ui-view="" class="content-ui"></div><script src="http://loader.tabix.io/master.js"></script></body></html>]]>
</http_server_default_response>
```
