Skip to main content
Version: 3.21.0

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.


TLS between APISIX and Upstream

Prerequisite(s)​

  • Install Docker.
  • Install cURL to send requests to the services for validation.
  • Install and run APISIX, or follow the Getting Started tutorial to start a new APISIX instance in Docker or on Kubernetes.

Create a Route With TLS Enabled​

Create a route to an example upstream httpbin.org on its default HTTPS port 443:

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"
}
}'

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​

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:

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
}
}
}'

❶ 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​

APISIX also supports TLS connection between clients and APISIX. See configure HTTPS between Client and APISIX.