title: Node.js 401 Error on nginx authentication
body: <p>Since few days I try to make work my angular application with an elasticsearch db behind an nginx authentication.
  If I remove the authentication my angular front works well but when I enable authentication I've 401 error. It's like application doesn't even send credentials. I've tested manually the credentials and it works. Thanks for your help. </p>
  
  <blockquote>
    <p>Angular code : 
          private connectWithAuth() {
            this.client = new elasticsearch.Client({
              hosts: [
                {
                  host: 'nginx.k8s-acc.pvcp.intra',
                  protocol: 'http',
                  port: 80,
                  auth: 'catalog2elastic:toto'
                }
              ],
              apiVersion: '6.4',
              log: 'trace'
            });
          }</p>
    
    <p>My nginx conf : </p>
  
  <pre><code>events {
      worker_connections 2048;
  }
  
  http {
    upstream elasticsearch {
      server elasticsearch:9200;
    }
  
    server {
      listen 80;
  
      location / {
        proxy_pass         http://elasticsearch;
        auth_basic         "Access limited";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_no_cache "0";
        proxy_cache_bypass $http_authorization;
      }
      location = /favicon.ico {
         log_not_found off;
      }
    }
  }
  </code></pre>
  </blockquote>
  
  <p>Detailed logs : </p>
  
  <blockquote>
    <p>"startedDateTime": "2020-02-21T13:56:57.958Z",
        "time": 23,
        "request": {
            "method": "OPTIONS",
            "url": "<a href="http://nginx.k8s-acc.pvcp.intra/cereq-1//_search" rel="nofollow noreferrer">http://nginx.k8s-acc.pvcp.intra/cereq-1//_search</a>",
            "httpVersion": "HTTP/1.1",
            "cookies": [],
            "headers": [
                {
                    "name": "Accept",
                    "value": "<em>/</em>"
                },
                {
                    "name": "Accept-Encoding",
                    "value": "gzip, deflate"
                },
                {
                    "name": "Access-Control-Request-Headers",
                    "value": "authorization, content-type"
                },
                {
                    "name": "Access-Control-Request-Method",
                    "value": "POST"
                },
                {
                    "name": "Cache-Control",
                    "value": "no-cache"
                },
                {
                    "name": "Connection",
                    "value": "Keep-Alive"
                },
                {
                    "name": "Content-Length",
                    "value": "0"
                },
                {
                    "name": "DNT",
                    "value": "1"
                },
                {
                    "name": "Host",
                    "value": "nginx.k8s-acc.pvcp.intra"
                },
                {
                    "name": "Origin",
                    "value": "<a href="http://catalog2elastic-acc.pvcp.intra" rel="nofollow noreferrer">http://catalog2elastic-acc.pvcp.intra</a>"
                },
                {
                    "name": "User-Agent",
                    "value": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727;
    .NET CLR 3.0.30729; .NET CLR 3.5.30729; wbx 1.0.0; Zoom 3.6.0)"
                }
            ],
            "queryString": [],
            "headersSize": 488,
            "bodySize": 0
        }</p>
  
  <pre><code>,
      "response": {
          "status": 401,
          "statusText": "Unauthorized",
          "httpVersion": "HTTP/1.1",
          "cookies": [],
          "headers": [
              {
                  "name": "Connection",
                  "value": "keep-alive"
              },
              {
                  "name": "Content-Length",
                  "value": "581"
              },
              {
                  "name": "Content-Type",
                  "value": "text/html"
              },
              {
                  "name": "Date",
                  "value": "Fri, 21 Feb 2020 13:56:57 GMT"
              },
              {
                  "name": "Server",
                  "value": "openresty/1.15.8.1"
              },
              {
                  "name": "WWW-Authenticate",
                  "value": "Basic realm=\"Access limited\""
              }
          ],
          "content": {
              "size": 581,
              "compression": -185,
              "mimeType": "text/html",
              "text": ""
          },
          "redirectURL": "",
          "headersSize": 185,
          "bodySize": 766
      },
      "cache": {},
      "timings": {
          "blocked": 0,
          "dns": -1,
          "connect": -1,
          "send": 0,
          "wait": 17,
          "receive": 5,
          "ssl": -1
      }
  </code></pre>
  </blockquote>