Comment exactement ce que je statique du serveur de fichiers avec nginx et gunicorn pour un Django app?

Droit maintenant, je suis en train de suivre ce tutoriel:

http://honza.ca/2011/05/deploying-django-with-nginx-and-gunicorn

Le modèle de site se charge correctement, mais les images ne se charge pas. Voici une partie de mon config.py fichier 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 nginx fichier de config (qui se trouve dans /etc/nginx/sites-enabled):

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 gunicorn_conf fichier:

bind = "0.0.0.0:8888"
logfile = "/home/lilo/textImageSite/gunicorn.log"
workers = 3

Et maintenant dans mon modèle, c'est la façon dont je suis l'accès de 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 n'arrive pas à comprendre quel est le problème avec ma configuration...

  • Oh oui, je vais essayer d'obtenir cette application sur xxx.xx.xxx.xx:8888/imageSite (adresse ip est cachée pour la confidentialité :D). Le seul problème est que l'application ne peut pas trouver l'image statique fichier sur le serveur, donc ça montre une image brisée
  • Qu'est-ce que dans le journal des erreurs?
  • Les fichiers statiques de ne pas être servi aussi longtemps que DEBUG=False stackoverflow.com/questions/5836674/...
InformationsquelleAutor Raymond | 2012-07-11