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>
        ServerName prod-domain.de
<Directory /opt/myproject/mysite/mysite> 
 <Files wsgi.py>
     Require all granted
  </Files>
</Directory>

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

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

My settings.py

DEBUG = True
ALLOWED_HOSTS = ["prod-domain.de"]

[...]

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 settings.py but apache doesn't show any error in the logs and now I stucked hardly.

Also tried

ALLOWED_HOSTS = ['*']

with no effect.

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

import os, sys

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

sys.path.append('opt/myproject/mysite')

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

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