Skip to content

Instantly share code, notes, and snippets.

@mcnemesis
Last active July 12, 2023 11:06
Show Gist options
  • Save mcnemesis/698211b8cfdd999f5831c7cff383455d to your computer and use it in GitHub Desktop.
Save mcnemesis/698211b8cfdd999f5831c7cff383455d to your computer and use it in GitHub Desktop.
Sample Mod-Macro spec for a single Django App running with Apache on a local subnet (useful to run apache behind nginx)
<Macro DJANGO_APP $IP $PORT $DOMAIN $ADMIN_EMAIL $PROJECT_DIR $APP >
NameVirtualHost $IP:$PORT
Listen $IP:$PORT
<VirtualHost $IP:$PORT>
ServerName $DOMAIN
ServerAlias www.$DOMAIN *.$DOMAIN
ServerAdmin $ADMIN_EMAIL
# to allow each django project to use its own nginx daemon and thus prevent sharing settings
# see: https://django.readthedocs.io/en/stable/howto/deployment/wsgi/modwsgi.html
WSGIDaemonProcess $DOMAIN processes=5 threads=1 display-name=$DOMAIN
WSGIProcessGroup $DOMAIN
WSGIApplicationGroup %{GLOBAL}
ErrorLog $PROJECT_DIR/logs/error.log
CustomLog $PROJECT_DIR/logs/access.log combined
WSGIScriptAlias / $PROJECT_DIR/$APP/wsgi.py
Alias /robots.txt $PROJECT_DIR/static/robots.txt
Alias /favicon.ico $PROJECT_DIR/static/favicon.ico
Alias /images $PROJECT_DIR/static/images
Alias /static $PROJECT_DIR/static
Alias /media/ $PROJECT_DIR/media/
Alias /css/ $PROJECT_DIR/static/css/
Alias /js/ $PROJECT_DIR/static/js/
Alias /img/ $PROJECT_DIR/static/img/
Alias /fonts/ $PROJECT_DIR/static/fonts/
AddType application/epub+zip .epub
#to allow mod_wsgi to pass on HTTP AUTH info to the app
WSGIPassAuthorization On
#So we can serve static and media files in production...
<Directory $PROJECT_DIR/static/>
Require all granted
</Directory>
<Directory $PROJECT_DIR/media/>
Require all granted
</Directory>
<Directory $PROJECT_DIR/$APP/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
</Macro>
<Directory /var/opt/>
Options FollowSymLinks
AllowOverride All
</Directory>
WSGIPythonPath /var/opt/qakbhs
# of course, we could have replaced the raw ip address with a human-friendly FQDN
USE DJANGO_APP 127.0.0.1 8888 13.51.70.187 joewillrich@gmail.com /var/opt/qakbhs website
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment