title: how to make Nginx forward https traffic to upstream as a https proxy server?
body: <p>Here I want to setup a tor cluster with a nginx as load balancer to provide HA tor service. I choose "<a href="https://github.com/reiz/nginx_proxy" rel="nofollow noreferrer">https://github.com/reiz/nginx_proxy</a>" the nginx module to provide https_proxy feature. It works well with the https connections. but didn't forward the https traffic to upstream.</p>
  
  <p>What happened:</p>
  
  <p>Case 1: </p>
  
  <p>When I run the cmd below, it will return a random ip from upstream tor services, it works well with http traffic.</p>
  
  <pre><code>curl -x localhost:8090 http://api.ipify.org
  </code></pre>
  
  <p>Case 2:</p>
  
  <p>It failed with the https traffic, what I can see from access log is </p>
  
  <pre><code>"CONNECT api.ipify.org:443 HTTP/1.1" 200 6176 "-" "curl/7.54.0" "-"
  </code></pre>
  
  <p>Yes, as a https proxy, nginx works, but failed to forward the https traffic to Tor upstream. The command below always return the same ip, the current ip of my pc.</p>
  
  <pre><code>curl -x localhost:8090 https://api.ipify.org
  </code></pre>
  
  <p>So, what I want is, how to make the nginx forward https traffic to upstream ?</p>
  
  <p>nginx.conf </p>
  
  <pre><code>user www-data;
  worker_processes  auto;
  daemon off;
  
  events {}
  
  
  http {
  
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
  
      access_log  /var/log/nginx/access.log  main;
      error_log /var/log/nginx/error.log;
      include /usr/local/nginx/conf/conf.d/*.conf;
  }
  </code></pre>
  
  <p>default.conf</p>
  
  <pre><code>upstream torProxy {
      server tor-cluster_tor_1:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_2:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_3:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_4:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_5:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_6:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_7:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_8:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_9:8118 max_fails=3 fail_timeout=30s;
      server tor-cluster_tor_10:8118 max_fails=3 fail_timeout=30s;
  }
  
  server {
      listen      8090;
      proxy_connect;
      proxy_max_temp_file_size 0;
      resolver 8.8.8.8;
      location / {
          proxy_pass http://torProxy;
          proxy_set_header Host $http_host;
          proxy_set_header Authorization "";
      }
  }
  </code></pre>