Getting 400 'bad request' for deployed django app with apache2 + mod_wsgi

I am running 2 django apps on same server (both are almost the same). First app is running without any issue in virtual env and prod mode. But for the 2nd deployed app I am getting the bad request error even its running in virtual env without any issue.

I set 775 for the whole project and www-data as owner.

My apache .conf file is

<VirtualHost *:80>
<Directory /opt/myproject/mysite/mysite> 
     Require all granted

Alias /media/ /opt/myproject/mysite/media/
Alias /static/ /opt/myproject/mysite/base/static/
<Directory /static/>
        Require all granted
<Directory /media/>
        Require all granted

ErrorLog ${APACHE_LOG_DIR}/error-myproject.log
CustomLog ${APACHE_LOG_DIR}/access-myproject.log combined
WSGIScriptAlias / /opt/myproject/mysite/mysite/
WSGIPythonPath /opt/myproject/mysite/env/lib/python3.8/site-packages


DEBUG = True


STATIC_ROOT = BASE_DIR / 'base/static/'

STATICFILES_DIRS = [BASE_DIR / 'myproject/static/', ]

STATIC_URL = 'static/'

# Base url to serve media files
MEDIA_URL = 'media/'

# Path where media is stored
MEDIA_ROOT = BASE_DIR / 'media/'

I played around a lot with apache conf and the but apache doesn't show any error in the logs and now I stucked hardly.

Also tried


with no effect.

Fixed after moved WSGIScriptAlias inside the VirtualHost tag in my apache .conf file and following on

import os, sys

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Back to Top