title: Node .js server with nginx and basic auth
body: <p>I'm trying to run a node.js server behind nginx, with a basic auth. Here is my minimal config:</p>
  
  <pre><code>server {
    auth_basic "closed website";
    auth_basic_user_file /etc/nginx/.htpasswd;
  
    location / {
      proxy_pass  http://localhost:3000/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }
  </code></pre>
  
  <p>My first problem is that when I go to the x.x.x.x, the basic auth form re-appears every time (indefinitely) I hit enter (whatever I set as login and password - even the good ones).</p>
  
  <p>The server simply returns some plain text <code>res.end("Hello World\n");</code>, which I can see for a second before the basic auth form appears again.</p>
  
  <p>Second question, is it possible to block the x.x.x.x:3000 (if not, there is no point in setting an auth on :80).</p>
  
  <p>Thanks!</p>
  
  <p>Btw it's the first time I setup nginx (and i spent quite a lot of time on it already).</p>
  
  <p>Note: it works without a basic auth (or with <code>auth_basic off;</code> in my location).</p>
  
  <p>Currently my website looks always like that:
  <a href="https://i.stack.imgur.com/9PKHI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9PKHI.jpg" alt="enter image description here"></a>
  :)</p>