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

931
Views
Nginx y Angular Routing (no se pueden encontrar archivos .js)

Nos encontramos con un problema al mostrar correctamente las páginas de las rutas de Angular servidas con Nginx. En nuestro proyecto Angular, nuestro href base es "/dashboard". El proyecto tiene dos rutas diferentes que apuntan a "/dashboard/data-analysis" y "/dashboard/data-visual".

Aquí está mi archivo nginx.conf básico:

 server{ listen 80; server_name localhost; location /dashboard/ { alias C:/Users/C123/Desktop/html/dashboard; index index.html; try_files $url $url/ /dashboard/index.html; } }

Cuando entro en "localhost/dashboard/" o "localhost/dashboard/data-analysis", cualquiera de las páginas cargará index.html desde "C:/Users/C123/Desktop/html/dashboard/", pero luego fallará cargue "polyfill.js" "runtime.js" "style.js", etc. como se define en la etiqueta <script> de index.html.

Además, Nginx intenta cargar esos archivos desde "C:/Users/C123/nginx/nginx-1.16.1/html/" en lugar de mi alias (C:/Users/C123/Desktop/html/dashboard).

¿Hay alguna forma en que pueda definir dentro del bloque de ubicación "dashboard/" donde leerá todo desde el index.html de mi alias? No quiero definir la raíz afuera, o un bloque de ubicación secundario solo para archivos ".js".

ACTUALIZAR (esta solución funcionó para mí):

 server{ listen 80; server_name localhost; location /dashboard/ { root C:/Users/C123/Desktop/html/ try_files $uri $uri/ /dashboard/index.html/ }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Probablemente podría establecer baseHref y desplegarUrl en angular.json. Puede configurarlo en proyectos -> $ nombre del proyecto -> arquitecto -> construir -> opciones.

 "deployUrl": "/dashboard/", "baseHref": "/dashboard/",

Consulte la respuesta para obtener más contexto sobre para qué sirven estos parámetros.

over 4 years ago · Santiago Trujillo Report

0

Te falta la directiva root .

Además, try_files debería intentar cargar el archivo indicado, o el index.html en el directorio.

No probado, pero debería funcionar:

 server { listen 80; server_name localhost; location /dashboard/ { root C:/Users/C123/Desktop/html; try_files $uri $uri/index.html =404; } }

Editar:

Si está intentando acceder a los archivos en el directorio del dashboard sin especificar la palabra dashboard en su solicitud, puede agregar un bloque para que esto sea una alternativa.

 server { listen 80; server_name localhost; # this will serve requests like http://localhost/runtime.js location / { root C:/Users/C123/Desktop/html/dashboard; try_files $uri $uri/index.html =404; } # this will serve requests like http://localhost/dashboard/ location /dashboard/ { root C:/Users/C123/Desktop/html; try_files $uri $uri/index.html =404; } }

Tenga en cuenta que cuando NGINX elige el contexto de ubicación, tomará la coincidencia más larga de las ubicaciones prefijadas mencionadas.

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!