[Solved]-Django Apache mod_wsgi 500

12👍

Turns out I needed to add my IP address to the “ALLOWED_HOSTS” in my settings.py file. Thanks to the error logging, I was finally able to see that.

Actual code:

ALLOWED_HOSTS = ['my.server.ip.address']

After an Apache restart, everything is working properly now!

9👍

You could try logging everything to a file to naildown the cause.

Add a logfile for django on the system :

sudo mkdir /var/log/django
sudo touch /var/log/django/error.log
sudo chown <user>:<user> /var/log/django/error.log
chmod 600 /var/log/django/error.log

Then add this in settings.py :

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'logfile': {
            'class': 'logging.handlers.WatchedFileHandler',
            'filename': '/var/log/django/error.log'
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'django': {
            'handlers': ['logfile'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}

Et voilà! Just run your django server & less /var/log/django/error.log tells you what’s wrong.

👤Matt

Leave a comment