title: Nginx reverse proxying to HTTPS upstream getting 502 Bad Gateway?
body: <p>I have this configuration:</p>
  
  <pre><code>upstream frontend_upstream {
      # FrontEnd part based on `frontend` container with React app.
      server frontend:3000;
  }
  
  server {
      ...
      listen 80;
      server_name  stage.example.com;
  
      server_tokens off;
  
      location /.well-known/acme-challenge/ {
          root /var/www/certbot;
      }
  
      location / {
          # Define the location of the proxy server to send the request to
          # Web it's a name of Docker container with a frontend.
          proxy_pass https://frontend_upstream;
  
          ...
      }
  
      # Setup communication with API container.
      location /api {
          proxy_pass http://api:9002;
          rewrite "^/api/(.*)$" /$1 break;
          proxy_redirect     off;
      }
  }
  server {
      listen 443 ssl;
      server_name stage.example.com;
      server_tokens off;
  
      ssl_certificate /etc/letsencrypt/live/stage.example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/stage.example.com/privkey.pem;
      include /etc/letsencrypt/options-ssl-nginx.conf;
      ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
  
      location / {
          proxy_pass  http://frontend_upstream;
          proxy_set_header    Host                $http_host;
          proxy_set_header    X-Real-IP           $remote_addr;
          proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
      }
  }
  </code></pre>
  
  <p>I want to be able to connect to my application via HTTP and HTTPs, but <code>SSL_do_handshake() failed (SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number) while SSL handshaking to upstream</code> raises.</p>
  
  <p>What is wrong with this configuration?
  There are a lot of similar issues, but none of them helps me.</p>