Score:0

Serving Django App with Apache 2 on Virtual Host

us flag

I am learning the Django framework and can run my first app on the development server using:

python3 manage.py runserver

enter image description here

However, what I really want to do is serve my app with Apache so it can be accessed from the web. My Apache Virtual Host is:

<VirtualHost *:443>
    ServerName django.example.com
    DocumentRoot /var/www/django/hello_world/mysite
    WSGIScriptAlias / /var/www/django/hello_world/mysite/mysite/wsgi.py

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/django.example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/django.example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/django.example.com/chain.pem

    WSGIDaemonProcess django.sample.com processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/django/hello_world/mysite/venv/lib/python3.6
    WSGIProcessGroup django.sample.com

    <directory /var/www/django/hello_world/mysite>
        AllowOverride all
        Require all granted
        Options FollowSymlinks
    </directory>
</VirtualHost>

As you can see, this is not a complicated app I'm trying to run, just the default Django start page, but I'm getting:

enter image description here

My settings.py file is:

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = 'django-insecure-3b^iz&pognt=yt5m&(!w@keo&*@a9zb&)$n@32v!yj4w%c!k-4'

DEBUG = True

ALLOWED_HOSTS = [ 'django.sample.com' ]

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'

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',
    },
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

I'm running Apache 2.4.6, CentOS 7. Thank you for any help.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.