title: Nginx returns 404 after loggin in with basic authentication
body: <p>I've created a website with next.js and after deployment in my own test server , everything worked as expected.As there is and admin Area, i made a configuration to protect the <code>/admin</code> <code>url</code> using nginx basic auth.Here are my steps:</p>
  
  <ol>
  <li>First i've installed the <code>apache2-utils</code> using <code>sudo apt-get install apache2-utils</code> on <code>Ubuntu 18.04</code></li>
  <li>I've created my credentials by running: <code>htpasswd /etc/nginx/.htpasswd myusername</code> .After click on <code>enter</code>, i've provided a <code>password</code></li>
  <li>I tried view the file content and everythinh was good because i've seen <code>usename:hashedpassword</code></li>
  <li><p>I made the following configuration in <code>nginx</code></p>
  
  <p><code>location /admin {
  auth_basic "Zone protege";
  auth_basic_user_file /etc/nginx/.htpasswd;
  }</code></p></li>
  </ol>
  
  <p>Here is my full configuration for that app.But i've hidden other configuration details(TLS,http redirect,etc..) :</p>
  
  <pre><code> server {
      server_name mydomainename.com;
      location / {
          proxy_pass http://localhost:3000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
       }
  
  
      location /admin {
          auth_basic "Zone protege";
          auth_basic_user_file /etc/nginx/.htpasswd;
          try_files $uri $uri/ =404;
        } 
  }
  </code></pre>
  
  <p>When i try to access the protected page,i get this :
  <a href="https://i.stack.imgur.com/okMsJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/okMsJ.png" alt="Login Popup"></a></p>
  
  <p>When i tap bad credentials i don't get the request page as expected.</p>
  
  <p>So when i tap the expected credentials i get a <code>404</code>:
  <a href="https://i.stack.imgur.com/HzCmB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HzCmB.png" alt="404 Error"></a></p>
  
  <p>I've already read the follwing solutions:
  <a href="https://www.digitalocean.com/community/questions/nginx-auth_basic-is-giving-me-a-404-not-found-message" rel="nofollow noreferrer">NGINX auth_basic is giving me a '404 not found' message ...</a>
  <a href="https://stackoverflow.com/questions/55044955/nginx-htpasswd-404-not-found">NGINX htpasswd 404 not found</a></p>
  
  <p>A tried other solutions as well even thaugh they aren't marked as solving the problem.</p>