Apache with WSGI and two Django apps with different sub domains
I have two django apps that I wanted to host on the same AWS server.
I assume that you are familiar with Django and Apache. So I will go and dive in right to it.
Apache configuration
myapp.conf
<VirtualHost *:80>
WSGIDaemonProcess myapp python-path=/home/ubuntu/MYAPP python- home=/home/ubuntu/MYAPP/.venv
WSGIProcessGroup myapp
WSGIApplicationGroup im
WSGIScriptAlias / /home/ubuntu/MYAPP/myapppro/appwsgi.py
ServerName first.domain.com
<Directory /home/ubuntu/MYAPP/myapppro>
<Files appwsgi.py>
Require all granted
</Files>
</Directory>
Alias /static /home/ubuntu/MYAPP/static
<Directory /home/ubuntu/MYAPP/static>
Require all granted
</Directory>
Alias /media /home/ubuntu/MYAPP/media
<Directory /home/ubuntu/MYAPP/media>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
secondapp.conf
<VirtualHost *:80>
WSGIDaemonProcess secondapp python-path=/home/ubuntu/SECONDAPP python- home=/home/ubuntu/SECONDAPP/.venv
WSGIProcessGroup secondapp
WSGIApplicationGroup second
WSGIScriptAlias / /home/ubuntu/SECONDAPP/myapppro/appwsgi.py
ServerName second.domain.com
<Directory /home/ubuntu/SECONDAPP/myapppro>
<Files appwsgi.py>
Require all granted
</Files>
</Directory>
Alias /static /home/ubuntu/SECONDAPP/static
<Directory /home/ubuntu/SECONDAPP/static>
Require all granted
</Directory>
Alias /media /home/ubuntu/SECONDAPP/media
<Directory /home/ubuntu/SECONDAPP/media>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
WSGI configuration
example of MYAPP/myapppro/appwsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapppro.appsettings'
application = get_wsgi_application()
example of MYAPP/myapppro/appsettings.py
from .settings import *
import os
DEBUG=True
WSGI_APPLICATION = 'myapppro.appwsgi.application'
Comments
Post a Comment