title: client sent plain HTTP request to HTTPS port while reading client request headers error when connecting to Nginx using java.net.Proxy
body: <p>I'm using java.net.Proxy to connect to my server via Nginx proxy. The Nginx proxy is SSL enabled. My server URL is https.</p>
  
  <p>When I try the example code below I'm getting 400 error:</p>
  
  <blockquote>
    <p>client sent plain HTTP request to HTTPS port while reading client request headers</p>
  </blockquote>
  
  <p>This is probably happening since I cannot specify in the code "https" as the proxy ip address so Nginx proxy thinks its an http request, and generates the error.</p>
  
  <p>It works fine when Nginx proxy SSL is disabled or when I connect directly to my server.</p>
  
  <p>Can this be solved programatically, or only by configuring the Nginx proxy to redirect http requests to https ?</p>
  
  <pre><code>String url = "https://myserver.com"; 
  Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.2.3.4", 444)); 
  HttpURLConnection con = (HttpURLConnection) (new URL(url).openConnection(proxy)); 
  con.connect();
  </code></pre>