- 1 year ago
Multiple django instances on Apache Windows using the same virtual host
To configure multiple Django instances on Apache running on Windows with the same virtual host, you can utilize Apache's VirtualHost
directive along with different WSGIScriptAlias
and WSGIDaemonProcess
settings for each Django application. Here's an example configuration:
Open the Apache configuration file: Locate and open the Apache configuration file, typically named
httpd.conf
, using a text editor.Enable the required modules: Make sure the following Apache modules are enabled:
bashLoadModule wsgi_module modules/mod_wsgi.so
LoadModule alias_module modules/mod_alias.so
If any of these modules are commented out, remove the leading '#' to enable them.
Configure the virtual host: Inside the
<VirtualHost>
section, specify the common settings for the virtual host, such as the server name and document root. For example:apache<VirtualHost *:80>
ServerName example.com
DocumentRoot "C:/path/to/document/root"
</VirtualHost>
Add WSGIScriptAlias for each Django instance: Inside the
<VirtualHost>
section, add separateWSGIScriptAlias
directives for each Django instance, pointing to the corresponding WSGI script file. Ensure that the paths match the directory structure of your Django projects. For example:apacheWSGIScriptAlias /app1 "C:/path/to/app1/app1/wsgi.py"
WSGIScriptAlias /app2 "C:/path/to/app2/app2/wsgi.py"
Configure WSGIDaemonProcess for each Django instance: Below the
WSGIScriptAlias
directives, define separateWSGIDaemonProcess
settings for each Django instance. Specify a unique name, process group, and other desired options for each instance. For example:apacheWSGIDaemonProcess app1 processes=2 threads=15 display-name=app1
WSGIDaemonProcess app2 processes=2 threads=15 display-name=app2
Assign WSGIProcessGroup to each Django instance: Inside the
<VirtualHost>
section, assign the respectiveWSGIProcessGroup
to eachWSGIScriptAlias
directive. For example:apacheWSGIProcessGroup app1
<Location "/app1">
Order allow,deny
Allow from all
</Location>
WSGIProcessGroup app2
<Location "/app2">
Order allow,deny
Allow from all
</Location>
Restart Apache: Save the configuration file and restart the Apache service to apply the changes.
By following these steps, you should be able to run multiple Django instances on Apache with the same virtual host. Each instance will have its own WSGI script, WSGI daemon process, and URL path under the virtual host.