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

325
Views
nginx buscando archivos estáticos en el lugar equivocado

mi implementación de Django con ec2, nginx y gunicorn funcionó bien además de que mis archivos estáticos no se cargan, el navegador muestra un error 404. Y esto se debe a que nginx se ve en un lugar completamente diferente al de la estática. En este punto, he probado muchas configuraciones y nada funciona. Me pregunto si un par de ojos nuevos pueden detectar un error aquí que yo no.

/sitios habilitados/django.conf:

 server { server_name site.net www.site.net; location /static/ { autoindex on; alias /home/ubuntu/saas/static/; } location / { include proxy_params; proxy_pass http://unix:/home/ubuntu/saas/app.sock; } location ~ \.css { add_header Content-Type text/css; } location ~ \.js { add_header Content-Type application/x-javascript; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/site.net/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/site.net/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = www.site.net) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = site.net) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name site.net www.site.net; return 404; # managed by Certbot }

y mi django settings.py se ve así y collectstatics funciona bien.

 STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'staticfiles') ] STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Eliminé el archivo predeterminado, pero aún parece que nginx busca los archivos estáticos en el lugar equivocado de acuerdo con este error.log:

 2020/05/01 19:57:45 [error] 3502#3502: *6 open() "/usr/share/nginx/html/static/css/custom.css" failed (2: No such file or directory), client: 86.221.78.105, server: site.net, request: "GET /static/cs$

Reinicié el servidor, volví a cargar nginx, nada parece funcionar. ¿Alguien tiene una idea de lo que podría intentar en ese momento?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Por lo general, hay un archivo default.conf que se instala con nginx cuando instala con yum o apt . Estará en /etc/nginx/conf.d/default.conf o /etc/nginx/sites-enabled/default.conf . Elimine ese archivo y vuelva a cargar nginx con sudo systemctl reload nginx , y debería estar listo para desaparecer si hay otro archivo de configuración en su servidor que no conoce.

over 4 years ago · Santiago Trujillo Report

0

Esto es lo que hice para resolver el problema. Deshacerse del index.html predeterminado en /usr/share/nginx/html/ y ejecutar el script conf como:

 server { server_name site.net www.site.net; listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/site.net/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/site.net/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot location /static/ { autoindex on; alias /home/ubuntu/saas/static/; } location / { include proxy_params; proxy_pass http://unix:/home/ubuntu/saas/app.sock; } } server { if ($host = www.site.net) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = site.net) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name site.net www.site.net; return 404; # managed by Certbot } Although this seems to be a workaround it makes the trick
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!