I've been tasked with fixing some aspects of a django 1.3 site, that runs on Apache/PostgreSql on the server. I'm trying to set it up on my development machine, with a virtual environment with postgres and the internal python developer server.
I managed to get the site running and reading from my local pg instance, but I can't get it to recognize my static files, which are stored in /site_media
. The site will soon be rewritten to use django 1.6 and the proper /static
folder but for now I need to fix this site.
I also tried running it with nginx and gnunicorn but the result is the same, the site displays but with no style and all references to files in the static dir give a 404. further inspection of the 404 reveals that django is trying to resolve the resources with its router.
Here are the relevant settings:
settings.py:
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/nico/src/df2/datos/site_media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = 'http://localhost:8000/site_media/'
I also added the following config, to no avail:
INSTALLED_APPS = (
'django.contrib.staticfiles',
)
STATICFILES_DIRS = (
'/home/nico/src/df2/datos/site_media/',
)
STATIC_URL = 'http://localhost:8000/site_media'
nginx config file:
server {
server_name localhost;
access_log off;
location /site_media/ {
alias /home/nico/src/df2/datos/site_media;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
If you need any other config please tell me.
I'd prefer to run this purely from the python server, but a solution with gunicorn/nginx is also fine