Questo è il mio nginx config:Serve file statici con Nginx + Gunicorn + Django
server {
listen 80;
server_name localhost;
keepalive_timeout 5;
access_log /home/tunde/django-projects/mumu/nginx/access.log;
error_log /home/tunde/django-projects/mumu/nginx/error.log;
root /home/tunde/django-projects/mumu;
location/{
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8000;
}
}
mio settings.py assomiglia:
import os
settings_dir = os.path.dirname(__file__)
PROJECT_ROOT = os.path.abspath(os.path.dirname(settings_dir))
STATIC_ROOT = '/home/tunde/django-projects/mumu/STATIC/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static/'),
)
Il mio file supervisord.conf assomiglia:
[program: mumu]
command = /home/tunde/ENV1/bin/gunicorn -w 1 --bind=127.0.0.1:8000 mumu.wsgi:application
directory = /home/tunde/django-projects/mumu/
stdout_logfile= /home/tunde/django-projects/mumu/supervisor/logfile.log
stderr_logfile= /home/tunde/django-projects/mumu/supervisor/error.log
user = tunde
Il problema è che i file statici non vengono forniti e non ho idea di cosa sto facendo male. Un url come /static/css/styles.css restituisce un 404. L'aiuto sarà molto apprezzato.
Grazie @ Scott A causa di una precedente esperienza con Django ignorando qualche modo i file statici memorizzati in una cartella denominata "statica", che decide di cambiare la posizione e nomi per il mio statica File. Dopo il riavvio di nginx, la mia configurazione ha funzionato senza dover aggiungere il blocco di posizione suggerito. – Tundebabzy
Quando guardi il tuo file di log del supervisore, vedi le richieste per i file statici (img, css, javascript)? –
il mio file logfile.log ie stdout_logfile in supervisord.conf è completamente vuoto – Tundebabzy