# Configure Upstream HTTPS

*TLS (Transport Layer Security)* is a cryptographic protocol designed to secure communication between two parties, such as a web browser and a web server. Services often require TLS if traffic between the API gateway and upstream services is not considered secure or private.

APISIX can encrypt upstream traffic over HTTPS. Encryption alone does not establish that the upstream is trusted: enable certificate verification to check its certificate chain and hostname.

The following steps configure HTTPS between APISIX and an upstream service, then enable certificate chain and hostname verification.

<br />

![TLS between APISIX and Upstream](https://static.api7.ai/uploads/2023/05/10/YEowzK2g_tls-apisix-upstream.jpg)

<br />

## Prerequisite(s)[​](#prerequisites "Direct link to Prerequisite(s)")

* Install [Docker](https://docs.docker.com/get-docker).
* Install [cURL](https://curl.se/) to send requests to the services for validation.
* Install and run APISIX, or follow the [Getting Started tutorial](https://docs.api7.ai/apisix/getting-started.md) to start a new APISIX instance in Docker or on Kubernetes.

## Create a Route With TLS Enabled[​](#create-a-route-with-tls-enabled "Direct link to Create a Route With TLS Enabled")

Create a route to an example upstream [httpbin.org](https://httpbin.org) on its default HTTPS port `443`:

* Admin API
* ADC

```
curl -i "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \

  -H "X-API-KEY: ${ADMIN_API_KEY}" -d '

{

  "id": "quickstart-tls-upstream",

  "uri": "/ip",

  "upstream": {

    "scheme": "https",

    "nodes": {

      "httpbin.org:443": 1

    },

    "type": "roundrobin"

  }

}'
```

Give this example its own service name. ADC matches a service by name, so reusing `httpbin Service` updates that existing service even when the label is different. If you previously synchronized this example, delete the older `quickstart-tls-upstream` route on `httpbin Service` after synchronizing, and leave every other route on that service in place.

adc.yaml

```
services:

  - name: Upstream HTTPS Service

    labels:

      docs-example: upstream-https

    routes:

      - uris:

          - /ip

        name: quickstart-tls-upstream

    upstream:

      type: roundrobin

      scheme: https

      nodes:

        - host: httpbin.org

          port: 443

          weight: 1
```

ADC reconciles services as desired state. Preview only this example's labeled service and confirm that the diff contains no unintended updates or deletions:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=upstream-https
```

Synchronize the reviewed service configuration:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=upstream-https
```

## Test TLS between APISIX and Upstream[​](#test-tls-between-apisix-and-upstream "Direct link to Test TLS between APISIX and Upstream")

Send a request to the route:

```
curl -i "http://127.0.0.1:9080/ip"
```

An `HTTP/1.1 200 OK` response verifies that APISIX has successfully established a connection and communicated with the upstream service over HTTPS.

## Verify the Upstream Certificate[​](#verify-the-upstream-certificate "Direct link to Verify the Upstream Certificate")

APISIX can trust upstream certificates through a per-upstream `tls.ca_certs` list or a shared CA store loaded at startup. A per-upstream list replaces the shared store for that upstream. The shared `apisix.ssl.ssl_trusted_certificate` setting defaults to `system`, which resolves to a CA bundle available on the host.

To trust a private CA or a custom set of public roots, prepare a PEM bundle containing those roots. Place or mount it where every APISIX instance can read it, then configure its absolute path:

config.yaml

```
apisix:

  ssl:

    ssl_trusted_certificate: /usr/local/apisix/conf/trusted-ca-bundle.pem
```

The custom bundle should contain every root that APISIX still needs for HTTPS connections.

Reload APISIX to apply the configuration:

```
docker exec apisix-quickstart apisix reload
```

Update the upstream to verify the certificate and use a hostname covered by it:

* Admin API
* ADC

```
curl "http://127.0.0.1:9180/apisix/admin/routes/quickstart-tls-upstream" \

  -X PATCH -H "X-API-KEY: ${ADMIN_API_KEY}" \

  -d '{

    "upstream": {

      "pass_host": "rewrite",

      "upstream_host": "httpbin.org",

      "tls": {

        "verify": true

      }

    }

  }'
```

Update the service upstream in `adc.yaml`:

adc.yaml

```
services:

  - name: Upstream HTTPS Service

    labels:

      docs-example: upstream-https

    routes:

      - uris:

          - /ip

        name: quickstart-tls-upstream

    upstream:

      type: roundrobin

      scheme: https

      pass_host: rewrite

      upstream_host: httpbin.org

      tls:

        verify: true

      nodes:

        - host: httpbin.org

          port: 443

          weight: 1
```

Preview the same labeled service scope:

```
adc diff -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=upstream-https
```

Review the diff and confirm it contains only the intended service update, then synchronize it with the same scope:

```
adc sync -f adc.yaml \

  --include-resource-type service \

  --label-selector docs-example=upstream-https
```

❶ `pass_host` and `upstream_host` use `httpbin.org` for the upstream Host header and TLS name.

❷ `tls.verify` enables certificate-chain and hostname verification. APISIX uses `tls.ca_certs` when configured and otherwise uses the shared CA store.

Verification defaults and revocation

If `tls.verify` is omitted, the upstream follows the NGINX verification setting. Setting it to `false` disables verification for this upstream. When verification uses the shared CA store, APISIX also applies a configured `proxy_ssl_crl`, or `grpc_ssl_crl` for a gRPCS upstream.

Send a request to verify that APISIX can connect to the upstream with certificate verification enabled:

```
curl -i "http://127.0.0.1:9080/ip"
```

A successful response with verification enabled confirms that the TLS handshake passed the configured trust and hostname checks. An untrusted certificate or hostname mismatch fails the upstream handshake; inspect APISIX's error log when the request returns a gateway error.

## Next Steps[​](#next-steps "Direct link to Next Steps")

APISIX also supports TLS connection between clients and APISIX. See [configure HTTPS between Client and APISIX](https://docs.api7.ai/apisix/how-to-guide/traffic-management/tls-and-mtls/configure-https-between-client-and-apisix.md).
