How to Secure an API Gateway with TLS
An API gateway is the front door for many services. TLS has to be correct in two places: between clients and the gateway, and between the gateway and each backend. Teams often secure the first and leave the second as plain HTTP "because it is internal". That is a decision, not a default, and this guide helps you make it on purpose. Product names differ, so where a vendor setting matters, check the current documentation for exact options and limits.
API gateway TLS: pick a termination model
| Model | Client to gateway | Gateway to backend | Use when |
|---|---|---|---|
| Edge termination | TLS | Plain HTTP | Backends on a trusted private network and policy allows it |
| Re-encryption | TLS | TLS, certificate verified | Compliance needs encryption in transit everywhere |
| Passthrough | TLS to backend | Same TLS session | Backend must see the client certificate or you cannot inspect traffic |
| mTLS to backend | TLS | TLS with client certificate | Gateway must prove its identity to the service |
Re-encryption is the safest common choice. Passthrough means the gateway cannot read paths or headers, so it loses routing, rate limiting and auth features. Whatever you choose, write it down.
Step 1: Certificates for the public side
Clients connect to a public hostname such as api.example.com. Use a certificate for that name from a public CA. Free certificates are suitable; see getting one with Certbot, or the managed certificate feature of your cloud gateway, if it has one. If clients are mostly web apps, a wildcard can simplify things; here is how to get one.
API gateway TLS, step 2: protocol and cipher policy
Allow TLS 1.2 and 1.3 and disable older versions; TLS 1.0 and 1.1 are deprecated in RFC 8996. Most gateways expose a policy name or a list of versions; the available names change between releases, so read the current docs. Background is in Best TLS Configuration for Nginx and Apache and disabling TLS 1.0 and 1.1. If you have old clients that need an older version, find out who they are before you decide.
Step 3: Verify the backend certificate
Re-encryption only helps if the gateway checks what it connects to. If it accepts any backend certificate, an attacker inside the network can impersonate a service. Here is the idea using Nginx as a gateway:
location /orders/ {
proxy_pass https://orders.internal.example.com;
proxy_ssl_server_name on;
proxy_ssl_verify on;
proxy_ssl_trusted_certificate /etc/ssl/internal-ca.pem;
proxy_ssl_verify_depth 2;
}proxy_ssl_verify on is off by default in Nginx, which surprises many people. Cloud gateways have equivalent switches, sometimes named "verify backend certificate" or "skip certificate validation". Leave validation on, and give the gateway the CA that signed your internal certificates.
Step 4: Internal certificates
For backends, either use public certificates on internal hostnames (which needs DNS control), or run a private CA. Automated issuance matters here, because many backends means many certificates. Automate SSL Renewal with Certbot and Hooks shows one automated route, and automating certificate management covers the general approach.
Step 5: Client certificates and mTLS
Some APIs need clients to prove who they are, for example partner integrations. The gateway can require a client certificate and pass the verified identity to backends. See Configure mTLS for APIs: Client Certificates for the details.
Step 6: Add transport headers
- Send
Strict-Transport-Securityon responses to browser clients. - Redirect or reject plain HTTP on the public listener.
- Pass
X-Forwarded-Protoand the client address to backends, and make backends trust them only from the gateway. - Strip those headers from incoming client requests so they cannot be spoofed.
Step 7: Test the whole path
curl -vI https://api.example.com/health
openssl s_client -connect api.example.com:443 \
-servername api.example.com -briefCheck that the protocol is 1.2 or 1.3 and the chain verifies. To test the backend leg, run the same openssl s_client from the gateway host against the backend. The OpenSSL testing guide helps interpret output. Finally, put expiry alerts on both the public and internal certificates, because an expired internal certificate causes errors that look like a gateway outage.
Related reading: mTLS for APIs, TLS configuration for websites and free SSL on nginx.
Frequently Asked Questions
Should the gateway terminate TLS or pass it through?
Terminate at the gateway when it must read and route on the request. Pass through when the backend must see the client certificate itself, as with mTLS end to end.
Do I need a separate certificate for the backend hop?
Yes if the hop crosses a network you do not control, and it should be verified against a CA you trust either way. A gateway that skips backend verification accepts any certificate, including an attacker's.
Does a gateway need a paid certificate?
No. A free domain-validated certificate covers the public hostname, and an internal CA covers the backend hop.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.