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

919
Views
¿Cómo puedo servir archivos estáticos de Django a través del contenedor nginx Docker?

Durante el desarrollo, me gusta implementar archivos estáticos de Django en una configuración lo más cercana posible a la producción. Para lograr esto, envuelvo el backend de Django en una imagen ( Dockerfile ) y los archivos estáticos JS de frontend y Django de backend en otra imagen junto con nginx configurado como servidor web ( Dockerfile_nginx ). La configuración es la siguiente:

Estructura del sistema de archivos:

 <projekt-repo> /frontend /backend /static (generated with python manage.py collectstatic) settings.py manage.py nginx.conf Dockerfile Dockerfile_nginx

settings.py :

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

nginx.conf :

 server { listen 0.0.0.0:8080; root /var/www; location / { try_files $uri $uri/ /index.html; } } server { listen 0.0.0.0:8000; root /var/www/django; location /static/ { autoindex on; alias /var/www/django/static/; } }

Dockerfile_nginx :

 FROM nginx:1.17.8-alpine COPY nginx.conf /etc/nginx/conf.d/nginx.conf COPY edge_frontend/www /var/www COPY edge_backend/static /var/www/django/static

Si ejecuto la aplicación e intento iniciar sesión a través del sitio de administración de Django ( localhost:8000/admin ), el sitio no tiene el estilo adecuado y los estados de salida del registro

 backend | Not Found: /static/admin/css/base.css backend | Not Found: /static/admin/css/login.css backend | Not Found: /static/admin/css/responsive.css backend | Not Found: /favicon.ico backend | Not Found: /static/admin/css/base.css backend | Not Found: /static/admin/css/login.css backend | Not Found: /static/admin/css/responsive.css backend | Not Found: /favicon.ico

Obviamente, hay algún desajuste en la configuración que no puedo detectar en este momento. ¿Alguien puede ayudar?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

cree una carpeta en su proyecto con el nombre "estático" y luego

agregue en su configuración.py

 STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static')

o quieres otro camino?

over 4 years ago · Santiago Trujillo Report

0

Debe configurar BASE_DIR , STATIC_URL y STATIC_ROOT en settings.py como se muestra a continuación...

 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/'

Y ejecute python manage.py collectstatic

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!