I'm running Django in Fastcgi Mode
./manage.py runfcgi method=threaded host=127.0.0.1 port=8080
with Nginx
server {
listen 80;
server_name myhostname.com;
access_log /var/log/nginx/sample_project.access.log;
error_log /var/log/nginx/sample_project.error.log;
location /static/ { # STATIC_URL
alias /home/www/myhostname.com/static/; # STATIC_ROOT
expires 30d;
}
location /media/ { # MEDIA_URL
alias /home/www/myhostname/static/; # MEDIA_ROOT
expires 30d;
}
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:8080;
}
}
The admin url is
http://myhostname.com/admin/
I notice that every HTML link generated is wrong like this one below
...
Log out
...
Below my url.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'configuratore.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
It seems that Django is duplicating admin URL but i'm not understanding why.
Make sure to add fastcgi_param SCRIPT_NAME ""; to your location / block in nginx configuration. By default django prepends it's value to reversed urls, thus setting to empty url should make it work.
Related
I have a Django application running on nginx. This application use sockets, which (as far as I know) should be proxied. So I have troubles configuring nginx and other stuff. Same application works fine on Apache/2.4.7, so I assume that it is not a programming mistake.
Sockets using is based on Django-Channels and backend is very similar to code from Channels getting started.
For server configuration I used this manual.
In the beginning I had just one problem: I got 200 request answer instead of 101 on socket creation. After many manipulations (configuring and newer versions installing) and information collecting I came to current situation:
I start uwsgi separately for sockets:
uwsgi --virtualenv /home/appname/env/ --http-socket /var/run/redis/redis.sock --http-websock --wsgi-file /home/appname/appname/appname/wsgi.py
On this step on socket creation var socket = new WebSocket("ws://appname.ch/ws/64"); I get
WebSocket connection to 'ws://appname.ch/ws/64' failed: Error during WebSocket handshake: Unexpected response code: 502
and sure
2016/09/12 12:00:26 [crit] 30070#0: *2141 connect() to unix:/var/run/redis/redis.sock failed (13: Permission denied) while connecting to upstream, client: 140.70.82.220, server: appname.ch,, request: "GET /ws/64 HTTP/1.1", upstream: "http://unix:/var/run/redis/redis.sock:/ws/64", host: "appname.ch"
in nginx error log.
After chmod 777 /var/run/redis/redis.sock I get responce
WebSocket connection to 'ws://appname.ch/ws/64' failed: Error during WebSocket handshake: Unexpected response code: 404
and in uwsgi
[pid: 6572|app: 0|req: 1/1] 0.0.0.0 () {46 vars in 916 bytes} [Mon Sep 12 12:01:29 2016] GET /ws/64 => generated 3357 bytes in 24 msecs (HTTP/1.1 404) 2 headers in 80 bytes (1 switches on core 0)
nginx.conf file
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
redis.conf
daemonize yes
pidfile /var/run/redis/redis-server.pid
port 6379
unixsocket /var/run/redis/redis.sock
unixsocketperm 777
timeout 0
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /var/lib/redis
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
/etc/nginx/sites-enabled/appname
server {
listen 80;
server_name appname.ch, 177.62.206.170;
#charset koi8-r;
client_max_body_size 8M;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
include uwsgi_params;
uwsgi_pass unix:///home/appname/appname/app.sock;
#add_header Access-Control-Allow-Origin *;
}
location /ws/ {
#proxy_redirect off;
proxy_pass http://unix:/var/run/redis/redis.sock;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
location /static {
alias /home/appname/appname/static_files;
}
location /media {
alias /home/appname/appname/media;
}
}
uwsgi.ini
[uwsgi]
chdir=/home/appname/appname
env=DJANGO_SETTINGS_MODULE=appname.settings
wsgi-file=appname/wsgi.py
master=True
pidfile=/home/appname/appname/appname-master.pid
vacuum=True
max-requests=5000
daemonize=/home/appname/appname/uwsgi.log
socket=/home/appname/appname/app.sock
virtualenv=/home/appname/env
uid=appname
gid=appname
Django app settings.py
"""
Django settings for appname project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['.appname.ch', '177.62.206.170', '127.0.0.1']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'customers',
'projects',
'moodboard',
'channels',
'debug_toolbar',
'rest_framework',
'appname',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'appname.urls'
WSGI_APPLICATION = 'appname.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static_files'),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
AUTH_PROFILE_MODULE = 'customers.Customer'
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
]
}
LOGIN_REDIRECT_URL = '/accounts/home'
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [("localhost", 6379)],
},
"ROUTING": "appname.routing.channel_routing",
},
}
App urls
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from projects.views import ProjectViewSet
from customers.views import UserHomeView, RegistrationView, CustomerViewSet, UserViewSet
from moodboard.views import MoodBoardViewSet, BoardItemViewSet, BoardTextViewSet, ShareMoodBoardItem, LiveViewSet
from rest_framework import routers
from django.conf import settings
from django.conf.urls.static import static
router = routers.DefaultRouter()
router.register(r'projects', ProjectViewSet)
router.register(r'moodboards', MoodBoardViewSet)
router.register(r'items', BoardItemViewSet)
router.register(r'texts', BoardTextViewSet)
router.register(r'share', ShareMoodBoardItem)
router.register(r'customers', CustomerViewSet)
router.register(r'users', UserViewSet)
router.register(r'live', LiveViewSet)
urlpatterns = patterns('',
url(r'^$', 'appname.views.home', name='landing_page'),
url(r'^api/', include(router.urls)),
url(r'^accounts/login/$', auth_views.login, name='login'),
url(r'^accounts/logout/$', auth_views.logout, name='logout'),
url(r'^accounts/home/$', UserHomeView.as_view(), name='home'),
url(r'^accounts/register/$', RegistrationView.as_view(), name='registration'),
url(r'^admin/', include(admin.site.urls)),
url(r'^customers/', include('customers.urls')),
url(r'^projects/', include('projects.urls')),
url(r'^moodboard/', include('moodboard.urls')),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)root
nginx version: 1.6.2
Redis server version: 2.4.14
uwsgi version: 2.1
Django version: 1.8.0 'final'
Python version: 2.7.3
Seems 404 should not be a complicated error, but after many days of fixing I have no idea what the problem is and if I am on the right way generally.
First of all, do not ever try to create sock manually.
Just set up a path, and it will be created automatically.
This is example nginx and uwsgi conf:
server {
root /your/djang/app/main/folder/;
# the port your site will be served on
listen 80;
server_name your-domain.com *.your-domain.com # if you have subdomains
charset utf-8;
access_log /path/to/logs/if/you/have/access_log.log
error_log /path/to/logs/if/you/have/error_log.log
# max upload size
client_max_body_size 1G;
location /media/ {
alias /path/to/django/media/if/exist/;
}
location /static/ {
alias /path/to/django/static/if/exist/;
}
# Note three slash
location / {
uwsgi_pass unix:///home/path/to/sock/file/your-sock.sock
}
}
and this cna be your uwsgi config file
# suprasl_uwsgi.ini file
[uwsgi]
uid = www-data
gid = www-data
chmod-socket = 755
chown-socket = www-data
# Django-related settings
# the base directory (full path)
chdir = /your/djang/app/main/folder/
# Django's wsgi file
wsgi-file = /your/djang/app/main/folder/main-folder/wsgi.py;
# the virtualenv (full path)
home = /your/env/folder/;
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2
# the socket (use the full path to be safe
socket = /home/path/to/sock/file/your-sock.soc
logto = /path/to/logs/if/you/have/uwsgi_logs.log
All you have to do is just run this command:
uwsgi --ini your_uwsgi_file.ini # the --ini option is used to specify a file
If you are up for creating a socket manually you can use python.
Try:
python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('/tmp/test.sock')"
But this does not create a socket. The socket is created by the application if its missing when the web server requests for it.
So we only need to declare our nginx.conf files mapping
location /{
include uwsgi_params;
uwsgi_pass unix:///to/where/you wish/the/file.sock;
}
The server will run socket() command returning a file descriptor checkout man socket.
I am trying to deploy my django app on a subdomain, say example.djangoapp.com, everything works fine, except for my django admin site, when i click on the link that goes to the admin site, it routes to a different url. This happens when i use the admin url template tag, i.e. it routes to djangoapp.com/index instead of example.djangoapp.index.fcgi/login (which is the admin site).
After removing the admin url template tag, i put an absolute url to the to redirect to the admin site, this work fine and the admin site shows up, but its static files are not served. So i am stack in between.
I am deploying on server that runs fastcgi on shared hosting
My questions:
1)Option 1 (Using the admin url template tag):
How do i get django to redirect me to the correct admin site (www.example.djangoapp.index.fcgi/login) instead of redirecting me to (www.djangoapp.com/index).
2) When using absolute url:
Now i hardcoded the admin link within my home template index page, this works fine but the django admin static files are not served. How can they get served?
Pardom my ignorance but i have been struggling with this for weeks. I decided to hardcode the url but still the admin sites static files are not being served.
Below is my settings.py , urls.py and index.html(where i hardcoded the admin site url). This code is inline with option 2 above that has the hardcoded admin site url.
settings.py
WSGI_APPLICATION = 'cconnect_web.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'CONN_MAX_AGE': 3600,
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Africa/Cairo'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/cconnect/static/'
STATIC_ROOT = '/home4/techaven/public_html/cconnect/static'
FORCE_SCRIPT_NAME="/index.fcgi/"
Urls.py
from django.conf.urls import *
from django.conf.urls import include, url
from django.contrib import admin
from cconnect_frontEnd import views
from . import settings
#app_name = 'cconnect_frontEnd
urlpatterns = [
url(r'^$', views.index, name ='index'),
url(r'^backend/', include('Back_End.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':settings.STATIC_ROOT}),
]
urlpatterns += patterns('Back_End.views',
(r'^login/$', 'login_view'),
)
admin.site.site_header = 'Cconnect Administration.'
index.html
<body>
<div class="header-wrapper">
<nav>
<div class=nav-wrapper">
{% load staticfiles %}
<img src="{% static "cconnect_frontEnd/images/slide/logo.png" %}" alt="Conference Connect"/>
<ul class="right hide-on-med-and-down">
{% load admin_urls %}
<li>Sign In</li>
<li>Features</li>
<li>Videos</li>
</ul>
index.fcgi
import os
import sys
from flup.server.fcgi import WSGIServer
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, "/home4/techaven/public_html/cconnect/cconnect_web/")
os.chdir("/home4/techaven/public_html/cconnect/cconnect_web")
os.environ['DJANGO_SETTINGS_MODULE'] = "cconnect_web.settings"
WSGIServer(get_wsgi_application()).run()
.htaccess
AddHandler fcgid-script .fcgi
DirectoryIndex index.fcgi
RewriteEngine On
RewriteCond %{HTTP_HOST} ^cconnect\.techavenue137\.rw$ [OR]
RewriteCond %{HTTP_HOST} ^www\.cconnect\.techavenue137\.rw$
RewriteRule ^/?$ "http\:\/\/www\.techavenue137\.rw\/cconnect\/index\.fcgi" [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cconnect/
RewriteRule ^index\.fcgi$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^/static/
RewriteRule ^(.*)$ /cconnect/index.fcgi/$1 [L]
</IfModule>
Thank you for your help and once again pardon my stupid questions.
You'll need to add a rewrite rule to redirect the browser request to the actual static files for the admin page.
Below your last rewrite rule, add these lines:
RewriteCond "%{REQUEST_URI}" ".*/static/admin/.*"
RewriteRule "(.*)/cconect/(.*)" "$1/index.fcgi/$2" [R, L]
Here, the rewrite condition is saying that if the requested URI contains /static/admin then replace cconnect with index.fcgi and keep everything else the same. Mark it as a redirect [R] and stop rule processing if found [L]. I hope this solves your issue.
Disclaimer: I'm not very proficient in regex patterns and I have a basic understanding of Apache, so this solution might need to be tweaked. Have a look here if you need to adjust it.
I entirely fixed this issue by moving a different host, it was had to deploy and using fast cgi. I deployed to Digital Oceans and used Nginx to serve the static and media files.
EDITED TO SHOW UPDATED CONFIGURATION
No static files are being shown in Production. Files are showing correctly in Development
settings.py
BASE_DIR = os.path.dirname(__file__)
STATIC_ROOT = '/opt/soundshelter/static/'
print "Base Dir: " + BASE_DIR #this returns /opt/soundshelter/soundshelter/soundshelter
print "Static Root: " + STATIC_ROOT #this returns /opt/soundshelter/static/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
) #/opt/soundshelter/soundshelter/soundshelter/static
Files are being called in the applications with
<link href="{% static "css/portfolio-item.css" %}" rel="stylesheet">
Using Nginx and Gunicorn.
Nginx config:
server {
server_name 46.101.56.50;
access_log yes;
location /static {
autoindex on;
alias /opt/soundshelter/static/;
}
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"';
}
# error_log /opt/soundshelter/soundshelter/soundshelter/nginx-error.log;
}
Running python manage.py collectstatic reports files were successfully copied but are still not being displayed.
Deployment handled by Fabric
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
env.hosts = []
print "Here we go..."
def commit():
local("git add . && git commit")
def push():
local("git push origin master")
def prepare_deploy():
commit()
push()
def deploy():
code_dir = '/opt/soundshelter/soundshelter/'
with cd(code_dir):
run("git pull")
run("python manage.py collectstatic -v0 --noinput")
run("service nginx restart")
run("ps aux |grep gunicorn |xargs kill -HUP")
run("gunicorn -b PROD_IP soundshelter.wsgi:application")
commit()
push()
deploy()
First of all, it seems to me that your edited STATICFILES_DIRS points to the wrong folder, since you have /static/ folder, not /staticfiles/. Should be as it was originally:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Second, STATIC_ROOT should point to the static folder which will be served by webserver in pro (but preferably not in project folder). In your case:
STATIC_ROOT="/opt/soundshelter/soundshelter/soundshelter/static/"
I usually place static folder near the project one and use dynamic STATIC_ROOT instead of hardcoding:
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
#this will alow to collect your static files in /opt/soundshelter/soundshelter/staticfiles/static
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'staticfiles/static')
Now you should do collectstatic and it will collect all static files in the STATIC_ROOT directory.
In your Nginx Config did you try to set:
location /static {
instead of
location /static/ {
also make sure the user running nginx has read permissions to the static folder.
BAD SOLUTION - DO NOT USE IN PRODUCTION
https://docs.djangoproject.com/en/1.8/howto/static-files/
Adding this to urls.py did the trick
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I believe I have all the prerequisites correct to get the admin page to appear, i have double checked with a bunch of other stack overflow posts and cannot figure out my error. Any help is greatly appreciated.
So I have Django setup on my Apache server. I go to http://localhost/ and i get the IT WORKED! Page. However, as SOON as I uncomment the admin lines in settings.py and urls.py, I get the Django 404 Error. I think i am doing something wrong with the Aliases and links to the django admin folder. Here is my relevant code
httpd.conf (wsgi loadmodule is included)
Alias /media/ "c:/xampp/htdocs/django_ngs/media"
Alias /static/ "c:/Python27/Lib/site-packages/django/contrib/admin/static"
<Directory c:/xampp/htdocs/django_ngs>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / "c:/xampp/htdocs/django_ngs/mod.wsgi"
settings.py (relevant parts)
ADMINS = (
# ('user', 'myemail#gmail.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'djangodb', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'root',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
urls.py
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
Any ideas? Thanks in advance
For anyone also looking for a solution, I found the kink. In urls.py it should have been url(r'/admin/', include(admin.site.urls)) instead of url(r'^admin/', include(admin.site.urls)), (switching the carrot for the forward slash). This was not apparent in all of the other example url.py files I have looked at... Anyway thank you for your attention and attempt to help, i really appreciate your time. Make sure the directory to your admin content is correct!
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
The fix was in adding a static handler to the urlpatterns variable:
from django.conf import settings
if settings.DEBUG:
# static files (images, css, javascript, etc.)
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))