Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

298
Vistas
www in domain return timeout, after I add redirect using regex in nginx

I have nginx and I want to redirect non-www to www:

So I did it using regex, but the redirect seems to works I get the redirect, but www return timeout.

How can I solve this?

upstream wwwapp {   
    least_conn;                                                                                  
    server www-app:3000 weight=10 max_fails=3 fail_timeout=30s;
}

server {
    server_name ~^(?!www\.)(?<domain>.+)$;
    return  301 $scheme://www.$domain$request_uri;
}

server {                                                                                                  
    listen       80;                                                                                      

    location / {                                                                                         
        proxy_pass http://wwwapp;                                                                     
        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
2 Respuestas
Responde la pregunta

0

Easy.

server {                                                                                                  
    listen       80;                                                                                      

    if ($host ~ ^(?!www\.)(?<domain>.+)$) {
        return  301 $scheme://www.$domain$request_uri;
    }

    location / {                                                                                         
        proxy_pass http://wwwapp;                                                                     
        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 Denunciar

0

Your second server block does not have a server_name so it is unlikely to get selected to process any requests.

The first server block is the default and will get selected even if the regex does not match.

You should change the second server block, and either add a server_name statement or make it the default_server.

See this document for details.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda