Free SSL for a Reverse Proxy (Nginx)
A reverse proxy such as Nginx sits in front of one or more applications. It can terminate TLS, so one place holds the certificate and the apps behind it speak plain HTTP on a private network. This is easier to manage than putting a certificate in every app, but the apps must be told that the original request used HTTPS.
Layout
| Hop | Protocol | Certificate |
|---|---|---|
| Browser to proxy | HTTPS | Public certificate on the proxy |
| Proxy to application | HTTP on localhost or private network | None needed, or internal TLS if required |
Step 1: get a free SSL certificate on the reverse proxy
With certbot:
sudo certbot certonly --nginx -d app.example.com
If the proxy cannot be reached on port 80, use DNS validation instead. The basics are in creating and downloading a free certificate.
Step 2: Nginx server blocks
server {
listen 80;
server_name app.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
http2 on;
server_name app.example.com;
ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
The http2 on; directive is for recent Nginx versions. On older versions, put http2 on the listen line.
Step 3: Tell the app it is behind a proxy
Most frameworks need a setting to trust the forwarded headers. If they do not, they build http:// URLs and may redirect endlessly.
| Stack | Setting |
|---|---|
| Express (Node) | app.set('trust proxy', 1) |
| Django | SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') |
| Laravel | Configure trusted proxies |
| WordPress | Set $_SERVER['HTTPS'] from X-Forwarded-Proto in wp-config.php |
WebSockets
If the app uses WebSockets, add the upgrade headers inside the location block:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
Test
- Run the SSL checker on the public hostname.
- Check the redirect with the redirect checker. You want one 301 and then 200.
- Open the browser console on the app and look for mixed content.
- After enabling HSTS, only use includeSubDomains if every subdomain supports HTTPS. See the HSTS guide.
Free SSL reverse proxy: common problems
Redirect loop: the app redirects to HTTPS because it never sees the forwarded protocol. See the too many redirects guide. 502 Bad Gateway: the upstream is not running or listens on another port. Wrong client IP in logs: the app needs to trust X-Forwarded-For.
Check the public name, not just localhost
Test the name clients use, from a machine that is not the proxy: openssl s_client -connect app.example.com:443 -servername app.example.com -brief shows the protocol and whether the chain verified. A certificate that loads on the server itself can still be the wrong one in the browser if a second server block catches the hostname.
Hardening the proxy
Once it works, tighten it. Disable the Nginx version string with server_tokens off;, keep the TLS protocol list to 1.2 and 1.3, and block direct access to the application port from outside, so traffic can only arrive through the proxy. Bind the app to 127.0.0.1 rather than 0.0.0.0 where possible.
Add security headers at the proxy for all apps behind it, using the security headers checker to confirm the result. Set sensible timeouts and body size limits per location so a slow client cannot tie up the upstream.
Related reading: TLS for an MQTT broker and fixing certificate chain errors.
Frequently Asked Questions
Do I need SSL between the proxy and the app?
Not on localhost. On an untrusted network, use TLS or a private tunnel.
Can one proxy serve many domains?
Yes. Add a server block per hostname, each with its own certificate, or use a SAN or wildcard certificate.
How do renewals reach Nginx?
Certbot reloads Nginx through its deploy hook, or you add --deploy-hook "systemctl reload nginx".
What if the proxy and the app both redirect to HTTPS?
Leave the redirect to the proxy only. If the app also forces HTTPS and cannot see X-Forwarded-Proto, the two rules loop.
✅ 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.