Dynamically route mod_wsgi to mod_vhost_alias
Project description
mod-wsgi-van 🚐
Dynamically route mod_wsgi to mod_vhost_alias.
Features
- Isolate virtual environments between vhosts
- Automatically reload deployed vhosts
- Automatically unload deleted vhosts
Requirements
- Vhosts must be symlinks, which change on deploy.
- Apps must perform all
import
s andsys.path
dependent operations during setup.
Concerns
- Modules belonging to different vhosts are loaded into the same mod_wsgi process / thread by default.
- Built-in modules loaded by
mod_wsgi
remain shared between all apps in a process / thread.
Example
# /etc/apache2/sites-available/vhosts.conf
<VirtualHost *:80>
UseCanonicalName Off
ServerAlias *.domain.org
VirtualDocumentRoot "/var/www/%0/static"
WSGIDaemonProcess example
WSGIProcessGroup example
WSGIScriptAlias /example /var/wsgi/example.py
</VirtualHost>
# /var/wsgi/example.py
from mod_wsgi_van import Router
application = Router().application
mkdir -p /var/www/.builds/example.domain.org/1/static
mkdir -p /var/www/.builds/example.domain.org/1/wsgi
python -m venv /var/www/.builds/example.domain.org/1/.venv
/var/www/.builds/example.domain.org/1/.venv/bin/python -m pip install Flask
# /var/www/.builds/example.domain.org/1/wsgi/app.py
from flask import Flask
app = Flask(__name__)
...
ln -sf /var/www/.builds/example.domain.org/1 /var/www/example.domain.org
API
Router
- Attributes
base_path: str = "/var/www"
- The location of the vhosts.venv_name: str = ".venv"
- The name of the virtual environment directory inside the vhost.wsgi_dir: str = "wsgi"
- The name of the WSGI directory inside the vhost.module_name: str = "app"
- The name of the module inside of the WSGI directory.object_name: str = "app"
- The name of the object inside of the module.update_interval: float = 1.0
- The interval for polling symlinks in seconds.
- Methods
get_server_path(host_name: str) -> pathlib.Path
- Override to change the vhost naming scheme.get_venv_paths(path: pathlib.Path) -> list[pathlib.Path]
- Override to change the venv site packages locations.
- Attributes
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mod_wsgi_van-0.0.1.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for mod_wsgi_van-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9568c167dc8b82193bc11b01c7eafd7cd8e14b6a575e549cb7e4c46201dd177a |
|
MD5 | b0d73779e02de107836251fddf6e18c5 |
|
BLAKE2b-256 | 7cc21cd828a31c2c70e6a40539a2df72c38c99455c580003762be7699b7235e2 |