Skip to content

Instantly share code, notes, and snippets.

@bruth
Created November 3, 2011 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruth/1335433 to your computer and use it in GitHub Desktop.
Save bruth/1335433 to your computer and use it in GitHub Desktop.
Dynamic location-based mass hosting approach with maintenance mode
<VirtualHost *:80>
# Define a conventional location for where are apps are deployed
# Locations such as "/apps/foo" and "/apps/bar" will match result
# in "foo" and "bar", respectively, being the application "names".
WSGIScriptAliasMatch ^/apps/([^/]+) /usr/local/srv/apps/$1-env/$1/src/conf/wsgi/app.py
# This example derived from deployed multiple Django applications, thus
# the static and media directories are mapped here.
AliasMatch ^/apps/([^/]+)/static/(.*) /usr/local/srv/apps/$1-env/$1/src/_static/$2
AliasMatch ^/apps/([^/]+)/media/(.*) /usr/local/srv/apps/$1-env/$1/src/media/$2
# A trivial "maintenance mode" solution is to keep a directory around
# of static files for displaying a page while in maintenance mode.
AliasMatch ^/apps/([^/]+)/maintenance/(.*) /usr/local/srv/apps/$1-env/$1/maintenance/$2
RewriteEngine On
# This first set of conditions test whether a "MAINTENANCE_MODE" file
# exists in the project root (same where the maintenance directory
# lives) and redirects to the static maintenance location.
RewriteCond %{REQUEST_URI} ^/apps/([^/]+)/(.*)
RewriteCond %2 !^maintenance
RewriteCond /usr/local/srv/apps/%1-env/%1/MAINTENANCE_MODE -f
RewriteRule ^.*$ /apps/%1/maintenance/ [R,L]
# This set of conditions test whether a "MAINTENANCE_MODE" file
# does _not_ exist in the project root and redirects to the root
# location of the app.
RewriteCond %{REQUEST_URI} ^/apps/([^/]+)/maintenance/.*
RewriteCond /usr/local/srv/apps/%1-env/%1/MAINTENANCE_MODE !-f
RewriteRule ^.*$ /apps/%1/ [R,L]
</VirtualHost>
<VirtualHost *:80>
WSGIScriptAlias / /usr/local/srv/apps/app-env/app/src/conf/wsgi/app.py
Alias /static /usr/local/srv/apps/app-env/app/src/_static
Alias /media /usr/local/srv/apps/app-env/app/src/media
Alias /maintenance /usr/local/srv/apps/app-env/app/maintenance
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maintenance/.*
RewriteCond /usr/local/srv/apps/app-env/app/MAINTENANCE_MODE -f
RewriteRule ^ /maintenance/ [R,L]
RewriteCond %{REQUEST_URI} ^/maintenance/.*
RewriteCond /usr/local/srv/apps/app-env/app/MAINTENANCE_MODE !-f
RewriteRule ^ / [R,L]
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment