title: Proxy HTTP requests to an HTTPS server in nginx
body: <p>I would like to set up an nginx instance which would proxy HTTP requests starting in /api to an HTTPS server, but the /api URL segment should be omitted out.
  For example, the instance should listen to localhost:9817. And if it receives a request to <a href="http://localhost:9817/api/auth" rel="noreferrer">http://localhost:9817/api/auth</a>, it should proxy it as <a href="https://api.com:8443/auth" rel="noreferrer">https://api.com:8443/auth</a>.</p>
  
  <p>Here is my nginx config:</p>
  
  <pre><code>events {
      worker_connections  1024;
  }
  
  http {
      server {
          listen       9817;
          server_name  localhost;
  
          location /api {
              rewrite  ^/api(/.*) $1 break;
              proxy_pass https://api.com:8443;
              proxy_set_header Host $host;
              proxy_http_version 1.1;
          }
  
          location / {
              root  "D:/Project/dist";
              try_files $uri $uri/ /index.html;
          }
      }
  }
  </code></pre>
  
  <p>However, I get the following error in error.log:</p>
  
  <pre><code>2020/01/16 17:54:22 [error] 420512#426216: *31 peer closed connection in SSL handshake (10054: An existing connection was forcibly closed by the remote host) while SSL handshaking to upstream, client: 127.0.0.1, server: localhost, request: "POST /api/auth HTTP/1.1", upstream: "https://16.53.35.38:8443/auth", host: "localhost:9817", referrer: "http://localhost:9817/"
  </code></pre>
  
  <p>What is the reason for this error? How can I fix it or set up proxying as I want to?</p>