# HTTPS settings

> Turn on HTTPS, forced redirects, and HTTP/2 for a CDN domain, and adjust TLS versions and OCSP stapling.

HTTPS encrypts traffic between visitors and edge nodes. Before you turn it on, prepare a certificate that covers the domain in the [Certificate Center](https://docs.bitiful.com/en/certs-center/intro.md).

Entry point: **CDN › Static acceleration management (静态加速管理) ›** the domain's **Manage (管理) › HTTPS configuration (HTTPS 配置)**.

> **Note**
>
> You can't make changes while the domain is **Stopped (已停止)**. After each change, the status becomes **Deploying (部署中)**, which usually takes 30 seconds, and the change takes effect once the status returns to **Running (运行中)**.

## Turn on HTTPS

### Prepare a certificate

In **Certificate Center › Certificate management (证书中心 › 证书管理)** ([open](https://console.bitiful.com/certs/manage)), [request an auto certificate](https://docs.bitiful.com/en/certs-center/auto-cert.md) or [upload your own certificate](https://docs.bitiful.com/en/certs-center/custom-cert.md), and wait for the certificate to be deployed.

### Edit the HTTPS configuration

On the **HTTPS configuration** card, click **Edit (编辑)**, set **HTTPS configuration** to **On (开启)**, fill in the fields in the table below, and click **Save (保存)**.

### Verify

After the status returns to **Running**, check:

```bash
curl -I https://cdn.example.com/path/to/image.jpg

# View the certificate in use and its validity period
echo | openssl s_client -connect cdn.example.com:443 -servername cdn.example.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates
```

| Field                     | Values                                                                                                                                    | Description                                                                                                     |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| **HTTPS configuration**   | On, Off                                                                                                                                   | When off, HTTPS access is no longer served.                                                                     |
| **Certificate (证书)**      | Drop-down                                                                                                                                 | Lists only deployed certificates. Each domain uses one certificate.                                             |
| **Force redirect (强制跳转)** | **Off (关闭, default)**, **HTTP to HTTPS › 301 redirect (HTTP 跳转 HTTPS › 301跳转)**, **HTTP to HTTPS › 302 redirect (HTTP 跳转 HTTPS › 302跳转)** | Redirects HTTP requests to HTTPS. Browsers remember a 301 for a long time, so use 302 first if you're not sure. |
| **HTTP/2**                | On, Off                                                                                                                                   | On by default when you first turn on HTTPS.                                                                     |

After you save, the card shows **HTTPS certificate (HTTPS 证书)** and **Certificate information (证书信息)** (validity period).

### Certificate checks

The selected certificate is checked when you save:

| Message                                                                                       | What to do                                                                                                                                                                                                    |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| "所选证书不包含 …，它包含的域名是 …" (the selected certificate doesn't cover …, the domains it covers are …) | The certificate doesn't cover this CDN domain. Choose another certificate, or request one for this domain. A wildcard certificate `*.example.com` matches only first-level subdomains, not `a.b.example.com`. |
| "所选证书已于 … 过期" (the selected certificate expired on …)                                         | Choose another certificate, or renew the certificate and try again.                                                                                                                                           |
| "该证书处于部署中，请等待证书部署成功再操作" (this certificate is deploying, wait until it's deployed)             | Wait for the certificate to be deployed.                                                                                                                                                                      |
| "获取证书失败" (failed to get the certificate)                                                      | Refresh the page and select the certificate again.                                                                                                                                                            |

## TLS version control

On the **TLS version control (TLS 版本控制)** card, use the switches to select **TLSv1.0**, **TLSv1.1**, **TLSv1.2**, and **TLSv1.3**. Changes are submitted as soon as you toggle. HTTPS must be on first.

- What you set is a continuous range: from the lowest version that's on to the highest version that's on. Versions in between are always enabled.
- Keep at least one version. Turning all of them off shows "参数不合法" (invalid parameter).
- We recommend enabling only TLSv1.2 and TLSv1.3. Enable TLSv1.0 and TLSv1.1 only when you need to support very old devices.

For example, if you turn on only TLSv1.0 and TLSv1.3, all versions from 1.0 to 1.3 are actually enabled, and after you refresh the page all four switches are on.

## OCSP stapling

During the handshake, the edge node attaches the certificate status directly, so visitors don't need to query the certificate authority, which reduces the wait on the first connection. Control it with the switch on the **OCSP Stapling** card. Changes are submitted as soon as you toggle. HTTPS must be on first.

## How settings affect each other

> **Warning**
>
> Each time you save the **HTTPS configuration** card (with HTTPS on), the TLS versions reset to 1.0 to 1.3 and OCSP stapling resets to on. Save the HTTPS configuration first, then adjust TLS versions and OCSP. After you change the certificate, the forced redirect, or HTTP/2, check these two settings again.

- Before you turn off HTTPS, change the `https://` addresses in your pages and apps. If you used a 301 redirect before, browsers may still redirect to HTTPS.
- After a certificate is updated (automatic renewal, or you modify your own certificate), the CDN domains that use it switch to the new certificate automatically, and you don't need to save again. See [Deploy certificates](https://docs.bitiful.com/en/certs-center/deploy.md).

## Recommended configurations

| Scenario                | HTTPS configuration | Force redirect | HTTP/2 | TLS versions | OCSP stapling |
| ----------------------- | ------------------- | -------------- | ------ | ------------ | ------------- |
| Website and app assets  | On                  | 301 redirect   | On     | 1.2, 1.3     | On            |
| Support for old devices | On                  | Off            | On     | 1.0 to 1.3   | On            |

## FAQ

<details>
<summary>Are HSTS and HTTP/3 (QUIC) supported?</summary>

The console currently has no HSTS or HTTP/3 settings for CDN domains.

</details>

<details>
<summary>Can I configure both RSA and ECC certificates for one domain?</summary>

In the console, each domain can select only one certificate, either RSA or ECC. ECC performs better, and RSA is more compatible.

</details>

<details>
<summary>My certificate isn't in the drop-down</summary>

The drop-down lists only deployed certificates. Go to **Certificate management** and check the status of the dot before the certificate name. Certificates that are being requested, being deployed, or failed don't appear.

</details>

<details>
<summary>What happens when a certificate is about to expire?</summary>

Auto certificates renew automatically before they expire. For your own certificates, [replace them](https://docs.bitiful.com/en/certs-center/custom-cert.md) before they expire. An SMS reminder is sent to your account's phone number before expiry.

</details>
