Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

477
Views
Nginx: ruta en localhost

Quiero configurar Nginx para enrutar múltiples proyectos en localhost sin tocar el archivo de hosts en mi computadora.

Es decir, Nginx debería manejar al menos rutas

  1. http://localhost/proyecto-uno

  2. http://localhost/proyecto-dos

Encontré un ejemplo pero no funciona en mi caso:

 # /etc/nginx/conf.ddefault.conf server { listen 80; # server_name localhost; index index.html index.htm; location ~ ^/project-one { root /usr/share/nginx/html/project-one; # index index.html index.htm; } location ~ ^/project-two { root /usr/share/nginx/html/project-two; # index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }

Funciona si configuro solo una location en solo una barra y requiero root :

 # /etc/nginx/conf.ddefault.conf server { listen 80; # server_name localhost; index index.html index.htm; location / { root /usr/share/nginx/html/project-one; # index index.html index.htm; } }

Con esta configuración, muestra el archivo html del directorio project-one en http://localhost .

Estoy usando Docker para probar:

docker run --rm --name my-nginx -p 80:80 -v $(pwd)/sites:/etc/nginx/conf.d -v $(pwd)/html:/usr/share/nginx/html -d nginx

Entonces puedo cambiar el archivo default.conf para Nginx y la carpeta html en los directorios locales respectivamente y luego reiniciar: docker restart my-nginx

¿Cómo configurar más de una ubicación correctamente para múltiples raíces sin tocar el archivo de hosts ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Bueno, finalmente lo conseguí...

 server { listen 80; # server_name localhost; index index.html index.htm; location ~ ^/project-one { root /usr/share/nginx/html; # index index.html index.htm; } location ~ ^/project-two { root /usr/share/nginx/html; # index index.html index.htm; } }

Y ahora funciona como esperaba:

http://localhost/project-one

http://localhost/project-two

Cada solicitud se enruta a la carpeta diferente relativamente:

/usr/share/nginx/html/project-one/index.html

/usr/share/nginx/html/project-two/index.html

Gracias a @RichardSmith.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!