nginx proxy to an https upstream fails with wrong version number
Your error
SSL_do_handshake() failed (SSL: error:0A00010B:SSL routines::wrong version number) while SSL handshaking to upstream2 more lines it can showFix it fast
Most common cause, 1 of 3proxy_pass uses https:// for a port that serves plain HTTP
When the upstream is meant to be plain HTTP, which is usual for an app on the same host or a private network, switch the scheme to http://.
location / {
proxy_pass http://127.0.0.1:8080;
}Short answer
SSL_do_handshake() failed with ssl3_get_record:wrong version number while SSL handshaking to upstream means nginx spoke TLS because proxy_pass says https://, and the backend port answered in plain HTTP. nginx then returns 502. Probe the port with openssl s_client, then use http:// in proxy_pass or add ssl to the backend's listen line (nginx 1.30, 1.31).
Which cause do you have?
Find the upstream address in the config, then open the handshake nginx opens, by hand. A wrong version number from s_client as well means that port does not speak TLS, so no certificate setting will help.
grep -R -n -E "proxy_pass|grpc_pass" /etc/nginx/
openssl s_client -connect 127.0.0.1:8080 -brief </dev/nullThen find the line you see in this list and open its fix:
- 1proxy_pass uses https:// for a port that serves plain HTTP
s_client against the upstream fails with wrong version number, while curl over http:// to the same port gets a status code - 2The upstream nginx listens on the port without the ssl parameter
The backend is supposed to speak HTTPS, yet a handshake to its port gets plain text back - 3grpc_pass uses grpcs:// in front of a gRPC server without TLS
The failing location proxies gRPC, and the backend service was started without TLS
What does the error look like?
SSL_do_handshake() failed (SSL: error:0A00010B:SSL routines::wrong version number) while SSL handshaking to upstreamSSL_do_handshake() failed (SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number) while SSL handshaking to upstream502 Bad Gateway
Cause 1 of 3
proxy_pass uses https:// for a port that serves plain HTTP
You sees_client against the upstream fails with wrong version number, while curl over http:// to the same port gets a status code
Check
wrong version number on the upstream handshake usually means proxy_pass says https:// for a port that only serves plain HTTP. nginx takes the upstream protocol from that URL. On a new connection, OpenSSL reads the reply's first record header; an HTTP status line does not carry the TLS major version there, so OpenSSL decides it does not look like TLS. Compare both schemes against the port.
curl -sS -o /dev/null -w "%{http_code}\n" http://127.0.0.1:8080/
curl -sSk -o /dev/null -w "%{http_code}\n" https://127.0.0.1:8080/Fix
When the upstream is meant to be plain HTTP, which is usual for an app on the same host or a private network, switch the scheme to http://.
location / {
proxy_pass http://127.0.0.1:8080;
}Verify
Check the syntax, reload, and fetch a page through nginx.
sudo nginx -t && sudo systemctl reload nginx
curl -I https://example.com/Confirmed by nginx.org
Cause 2 of 3
The upstream nginx listens on the port without the ssl parameter
You seeThe backend is supposed to speak HTTPS, yet a handshake to its port gets plain text back
Check
wrong version number against a backend that should speak HTTPS means that backend's listen line lacks the ssl parameter. On the backend machine, a port becomes TLS only when its listen directive carries ssl, so read the listen lines for the port you proxy to.
grep -R -n "listen" /etc/nginx/sites-enabled/ /etc/nginx/conf.d/Fix
Add ssl to that listen line and give the server block a certificate and key; the front proxy can then keep https://.
server {
listen 8443 ssl;
ssl_certificate /etc/nginx/certs/backend.crt;
ssl_certificate_key /etc/nginx/certs/backend.key;
}Verify
Reload the backend and repeat the s_client probe against its port; it now prints a protocol and cipher.
sudo nginx -t && sudo systemctl reload nginx
openssl s_client -connect 127.0.0.1:8443 -brief </dev/nullConfirmed by nginx.org
Cause 3 of 3
grpc_pass uses grpcs:// in front of a gRPC server without TLS
You seeThe failing location proxies gRPC, and the backend service was started without TLS
Check
wrong version number in a gRPC location means grpc_pass uses grpcs:// while the gRPC server listens without TLS. The scheme picks the transport: grpc:// is plain and grpcs:// is gRPC over SSL, so the mismatch is the same one as with proxy_pass.
grep -R -n "grpc_pass" /etc/nginx/
openssl s_client -connect 127.0.0.1:9000 -brief </dev/nullFix
Write grpc:// for a plain backend, or enable TLS on the gRPC server and keep grpcs://.
location / {
grpc_pass grpc://127.0.0.1:9000;
}Verify
Reload nginx and make one gRPC call through it.
sudo nginx -t && sudo systemctl reload nginxConfirmed by nginx.org
How do I stop it coming back?
- Define each upstream's scheme and port in one include file, with a comment saying whether that port speaks TLS.
- Probe a new backend with openssl s_client before it goes into proxy_pass.
- Use plain http:// to an app on 127.0.0.1 and keep TLS on the public side, unless the hop crosses a network you do not trust.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, stegnor.com.