Mike IT Mike IT - 21 days ago 6
Apache Configuration Question

django static folder is not served in apache2

I have inherited a django application (1.7) and I am supposed to install it on Apache2. Everything runs fine when I do runserver from command prompt but as deploy to apache2/mod_wsgi.

I am pretty sure the STATICFILES_DIRS has been set correctly.

The settings.py is like below:

Django settings for sampleapp project.

Generated by 'django-admin startproject' using Django 1.10.3.

For more information on this file, see

For the full list of settings and their values, see

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'tf07wvjy+#g&&#s$spi34_c-jno^8_cb0bw=*dx2ni2+w6x-(h'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# ALLOWED_HOSTS = ['', 'localhost']
ALLOWED_HOSTS = ['', 'localhost']

# Application definition


# 'south',


ROOT_URLCONF = 'CordeliaHanelBackend.urls'

PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
# '/var/www/CordeliaHanelBackend-master/StudioHanel/templates/StudioHanel',
# )

'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/var/www/CordeliaHanelBackend-master/StudioHanel/templates/StudioHanel','CordeliaHanelBackend/templates'],
'APP_DIRS': True,
'context_processors': [

WSGI_APPLICATION = 'CordeliaHanelBackend.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/



USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_URL = '/static/'

# os.path.join(BASE_DIR, "static"),

# '/var/www/CordeliaHanelFrontend-master/www/app',
# '/var/www/CordeliaHanelBackend-master/StudioHanel/static',

# STATIC_ROOT = '/var/www/CordeliaHanelFrontend-master/www/app'


# DEFAULT_FILE_STORAGE = '/var/www/CordeliaHanelFrontend-master/www/app'

'default': 'south.db.sqlite3'

and here is the apache2 configuration site-available file.

<VirtualHost *:80>

WSGIDaemonProcess sampleapp python-path=/var/www/CordeliaHanelBackend-master:/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages
WSGIProcessGroup sampleapp
WSGIScriptAlias / /var/www/CordeliaHanelBackend-master/CordeliaHanelBackend/wsgi.py

# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf


Alias /static /var/www/CordeliaHanelFrontend-master/www/dist/
<Directory /var/www/CordeliaHanelFrontend-master/www/dist/>
Order allow,deny
Allow from all


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


You need to define path to your project in apache's configuration as:

<Directory /path/my/project/www/xyz.com>  # In your case: /var/www/CordeliaHanelBackend-master
    Require all granted
    AllowOverride All
    Options -Indexes