The day I spent 8 hours trying to do a NGINX proxy_pass between two servers

Miguel Treviño
3 min readSep 10, 2021

--

Ok I have to admit it… this issue was so dumb but I was so used to the fact that I never had issues with nginx configurations and a simple proxy_pass.

Every thing started because I am trying to setup an Angular App which resides in another dedicated server and I have a bunch of Node apps that receive all the workload from the clients.

I didn't want to have issues with CORS inside the Angular App so I decided to do what I always do… NGINX proxy pass that when I hit the /api route, it will understand that it has to go to the Node App Servers, simple as that, right?

Well I have been doing that for many projects so I didn't have any complications, till yesterday night when I decided to upload the project and tell my team to start testing it. Oh Surprise Miguel! You won't sleep tonight because the two servers can't communicate with each other.

My Approach was the following:

  1. I created the SSL certificates for app.myApp.com
  2. I continued with the SSL certificates for api.myApp.com
  3. I uploaded the code and git hooks for the automated deployments for both apps.
  4. tested both apps (node app and Angular app) separately and everything seemed to work just fine
  5. Setup scripts for deployment and final scripting changes for both apps
  6. setup NGINX Proxy pass to communicate with the Node apps

When I attempted to hit the endpoint I start getting the following error:

502 Bad Gateway

That took me by surprise because I didn't do anything different from the previous 20 configurations I have done, so what's different?!

I start checking everything related to the error in Google with my dear friend StackOverflow and I tried many solutions but nothing seemed to work, because I was reading the error logs from the Node App Servers instead from the Client app, and that's how I found out about the error…

Solution

I started reading now the logs from the Client app and I found the following

2021/09/10 19:27:46 [crit] 425561#425561: *22 SSL_do_handshake() failed (SSL: error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name:SSL alert number 112) while SSL handshaking to upstream, client: 190.32.233.122, server: app.myApp.com, request: “POST /v2/auth/login HTTP/1.1”, upstream: “https://142.224.134.211:443/v2/auth/login", host: “app.myApp.com”

so I found a random post about a Heroku app having a similar issue, I was tired and giving up so I decided to give it a chance and just read it and maybe it gives me a hint of what was the problem…

So I clicked on the second link and decided to read everything in there and found what this person is saying…

I did include that line of code inside my NGINX configuration for the app.myApp.com and it worked!

proxy_ssl_server_name on; 

And that's how a simple line of code gave me a huge headache!

Cheers!

--

--

Miguel Treviño
Miguel Treviño

Written by Miguel Treviño

I am a Senior Software Engineer currently working with biometrics and AI. I am the CTO at Verifik (https://verifik.co) & Zelf (https://zelf.world)

Responses (4)