title: Javascript get request from https server to localhost:port with self signed SSL
body: <p>I have two servers configured and running om my Debian server. One main server and one <a href="https://www.elastic.co/" rel="nofollow noreferrer">Elasticsearch</a> (search engine) server.</p>
  
  <p>The main server is running on a https node server with a NGINX proxy and a purchased SSL certificate. The Elasticsearch server is running on a http server. I've added a new NGINX proxy server to redirect <a href="https://localhost:9999" rel="nofollow noreferrer">https://localhost:9999</a> to <a href="http://localhost:9200" rel="nofollow noreferrer">http://localhost:9200</a> with a self-signed SSL certificate. There's also a configured authentication on the Elasticsearch server with a username and a password.</p>
  
  <p>Everything seem to be properly configured since I can get a successful response from the server when I'm doing a curl from the servers terminal towards <a href="https://localhost:9999" rel="nofollow noreferrer">https://localhost:9999</a> with the <strong>-k</strong> option to bypass the  verication of the self-signed certificate, without it, it does not work. </p>
  
  <p>I cannot do a cross-domain request from my https main server to my http localhost server. Therefore I need to configure https on my localhost server.</p>
  
  <hr>
  
  <p>Without the <strong>-k</strong> option:</p>
  
  <pre class="lang-sh prettyprint-override"><code>curl: (60) SSL certificate problem: self signed certificate
  More details here: http://curl.haxx.se/docs/sslcerts.html
  
  curl performs SSL certificate verification by default, using a "bundle"
   of Certificate Authority (CA) public keys (CA certs). If the default
   bundle file isn't adequate, you can specify an alternate file
   using the --cacert option.
  If this HTTPS server uses a certificate signed by a CA represented in
   the bundle, the certificate verification probably failed due to a
   problem with the certificate (it might be expired, or the name might
   not match the domain name in the URL).
  If you'd like to turn off curl's verification of the certificate, use
   the -k (or --insecure) option.
  </code></pre>
  
  <p>With the <strong>-k</strong> option:</p>
  
  <pre><code>{
    "name" : "server-name",
    "cluster_name" : "name",
    "cluster_uuid" : "uuid",
    "version" : {
      "number" : "x.x.x",
      "build_hash" : "abc123",
      "build_date" : "Timestamp",
      "build_snapshot" : false,
      "lucene_version" : "x.x.x"
    },
    "tagline" : "You Know, for Search"
  }
  </code></pre>
  
  <p>Which is a successful Elasticsearch server response.</p>
  
  <hr>
  
  <p>So the full curl request looks something like <code>curl -k https://localhost:9999/ --user username:password</code>.</p>
  
  <blockquote>
    <p>So, the actual question:</p>
  </blockquote>
  
  <p>I would like to be able to do a simple jQuery AJAX request towards this server. I'm trying with the following request <code>$.get('https://username:password@localhost:9999/')</code> but I'm getting <code>ERR_CONNECTION_REFUSED</code>.</p>
  
  <p>My guess is that that the AJAX request does not bypass the self-signed certificate verification and therefore it refuses to connect.</p>
  
  <p>Is there any simple way to solve this with request headers or something like that? Or do i need to purchase a CA-certificate to make this work with AJAX?</p>