En ce moment, je suis en train de suivre ce tutoriel:Comment puis-je server des fichiers statiques avec nginx et gunicorn pour une application Django?
http://honza.ca/2011/05/deploying-django-with-nginx-and-gunicorn
Les charges du site modèle correctement, mais les images ne se charge pas. Voici une partie de mon dossier de config.py pour mon application:
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/home/lilo/textImageSite/imageSite/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Mon fichier de configuration nginx (situé dans/etc/nginx/sites activés):
server {
listen 80;
server_name xxx.xx.xx.xx; #the actual IP of the server; it has a public IP address
access_log /home/lilo/textImageSite/access.log;
error_log /home/lilo/textImageSite/error.log;
location /static {
root /home/lilo/textImageSite/imageSite;
}
location/{
proxy_pass http://127.0.0.1:8888;
}
}
Mon fichier gunicorn_conf:
bind = "0.0.0.0:8888"
logfile = "/home/lilo/textImageSite/gunicorn.log"
workers = 3
Et maintenant dans mon modèle, voilà comment je suis accès à l'image:
<img src="{{STATIC_URL}}{{ choice.image_location}}" /> <br />
Voici ce que le code HTML généré ressemble:
<img src="/static/street_sign2.jpg" /> <br />
Désolé pour le mur de texte, mais je ne peux pas comprendre ce qui ne va pas avec ma configuration ...
Oh oui, j'essaie d'obtenir cette application sur xxx.xx.xxx.xx : 8888/imageSite (adresse IP cachée pour confidentialité: D). Le seul problème en ce moment est que l'application ne peut pas trouver le fichier d'image statique sur le serveur, donc il montre juste une image brisée – Raymond
Qu'est-ce qui se trouve dans le journal des erreurs? – VBart
Les fichiers statiques ne seront pas servis tant que 'DEBUG = False' http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access- échec – Montaro