Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

424
Visualizações
Nginx returns 404 after loggin in with basic authentication

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 /admin url using nginx basic auth.Here are my steps:

  1. First i've installed the apache2-utils using sudo apt-get install apache2-utils on Ubuntu 18.04
  2. I've created my credentials by running: htpasswd /etc/nginx/.htpasswd myusername .After click on enter, i've provided a password
  3. I tried view the file content and everythinh was good because i've seen usename:hashedpassword
  4. I made the following configuration in nginx

    location /admin { auth_basic "Zone protege"; auth_basic_user_file /etc/nginx/.htpasswd; }

Here is my full configuration for that app.But i've hidden other configuration details(TLS,http redirect,etc..) :

 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;
      } 
}

When i try to access the protected page,i get this : Login Popup

When i tap bad credentials i don't get the request page as expected.

So when i tap the expected credentials i get a 404: 404 Error

I've already read the follwing solutions: NGINX auth_basic is giving me a '404 not found' message ... NGINX htpasswd 404 not found

A tried other solutions as well even thaugh they aren't marked as solving the problem.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try this ?

server {
    server_name mydomainename.com;
    auth_basic "Zone protege";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location / {
        auth_basic off;

        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 on;

        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;
    } 
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda