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
- Symlinked vhost support
Overview
The router checks the HTTP_HOST on request to decide which vhosts it should be routed to. WSGI apps are lazy loaded. WSGI directories are monitored for mtime changes by default. Symlinks are resolved on access to support deploys that symlink vhosts.
Concerns
- Modules belonging to different vhosts are loaded into the same mod_wsgi process by default.
- Modules loaded outside of an app are shared between all apps in a process.
Install
sudo -H python -m pip install mod-wsgi-van
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/example.domain.org/static
mkdir -p /var/www/example.domain.org/wsgi
python -m venv /var/www/example.domain.org/.venv
/var/www/example.domain.org/.venv/bin/python -m pip install Flask
# /var/www/example.domain.org/wsgi/app.py
from flask import Flask
app = Flask(__name__)
...
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.get_version(path: pathlib.Path) -> Any
- Override to customize the change detection strategy.
- 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-1.0.0.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file mod_wsgi_van-1.0.0.tar.gz
.
File metadata
- Download URL: mod_wsgi_van-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4c3ffcec0d31ba32996a23fb42389fa42b1e2beb040c531cb59d35a106f0224 |
|
MD5 | 8e6a55f15ed319d222bbb0343011d571 |
|
BLAKE2b-256 | 635c25495eb19f3b96a4ae234a582df4dbe5aabd22ddd8f3e45a86235d675546 |
File details
Details for the file mod_wsgi_van-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: mod_wsgi_van-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23dbae7a9558531540e7746f3da38839d08e62fe321e985df333792a503c6008 |
|
MD5 | 0de156af22174d4b26120b587569ee21 |
|
BLAKE2b-256 | 244f55a4aaad6f07925c9388da99a659e1961aa6a6babe2369d681475484954d |