Additional Virtual Host causing WSGI application error

I have two different django applications running on the same apache2.4 server. One of the sites is working, but the new one i am trying to set up is giving me this same error:

Target WSGI script 'C:/vault90/vault90/wsgi.py' does not contain WSGI application 'application'.

The file at this location looks like this however:

import os
import sys
import logging
import traceback
from django.core.wsgi import get_wsgi_application

# Add your project directory to the sys.path
sys.path.append('C:/vault90')

# Set the settings module for the project
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vault90.settings')

# Setup logging for WSGI errors
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

try:
	# Get the WSGI application
	application = get_wsgi_application()
except Exception:
    logger.error('WSGI failed to start', exc_info=True)
    traceback.print_exc()

and this is my vhosts.conf:

<VirtualHost *:80>
    ServerName example2.com
    ServerAlias www.example2.com
    DocumentRoot "C:/vault90"

    # Point to the WSGI application
    WSGIScriptAlias / C:/vault90/vault90/wsgi.py

    LogLevel info wsgi:debug
    <Directory C:/vault90/vault90>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    # Serve static files
    Alias /static/ C:/vault90/static/
    <Directory C:/vault90/static>
        Require all granted
    </Directory>

    # Logs for debugging
    ErrorLog "C:/Apache24/logs/vault90_error.log"
    CustomLog "C:/Apache24/logs/vault90_access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "C:/tbg"

    # Point to the WSGI application
    WSGIScriptAlias / C:/tbg/tbg/wsgi.py

    LogLevel info wsgi:debug
    <Directory C:/tbg/tbg>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    # Serve static files
    Alias /static/ C:/tbg/static/
    <Directory C:/tbg/static>
        Require all granted
    </Directory>

    # Log files
    ErrorLog "C:/Apache24/logs/tbg_error.log"
    CustomLog "C:/Apache24/logs/tbg_access.log" common
</VirtualHost>

and my python path is here:

LoadFile "C:/Users/joeb/AppData/Local/Programs/Python/Python313/python313.dll"
LoadModule wsgi_module "C:/Users/joeb/AppData/Local/Programs/Python/Python313/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp313-win_amd64.pyd"
WSGIPythonHome "C:/Users/joeb/AppData/Local/Programs/Python/Python313"

I am sorry this is not super organized. but happy to edit if there is feedback or more details i should provide to make this more a logical oriented issue to resolve.

There are many things to check here…

Let’s start checking one by one…

So, the error message "Target WSGI script 'C:/vault90/vault90/wsgi.py' does not contain WSGI application 'application'," means that mod_wsgi can’t find an application instance named β€œapplication” in your wsgi.py.

I guess your project structure is something like this?!

C:/vault90/
    β”œβ”€β”€ vault90/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ settings.py
    β”‚   β”œβ”€β”€ urls.py
    β”‚   └── wsgi.py
    β”œβ”€β”€ manage.py
    └── static/

If so, try this path sys.path.append('C:/vault90/vault90')

Restart your server and post here your errors.

1 Like

Hey thanks for help!

my project structure is this atm:

C:/vault90
β”œβ”€β”€ manage.py
β”œβ”€β”€ print_tree_helper.py
β”œβ”€β”€ static
β”œβ”€β”€ templates
β”‚   └── landing_page.html
└── vault90
    β”œβ”€β”€ logs
    β”‚   β”œβ”€β”€ debug.log
    β”‚   └── error.log
    β”œβ”€β”€ settings.py
    β”œβ”€β”€ urls.py
    β”œβ”€β”€ views.py
    β”œβ”€β”€ wsgi.py
    β”œβ”€β”€ __init__.py
    └── __pycache__
        β”œβ”€β”€ settings.cpython-313.pyc
        β”œβ”€β”€ urls.cpython-313.pyc
        └── __init__.cpython-313.pyc

when i edit the wsgi.py:

# Add your project directory to the sys.path
- sys.path.append('C:/vault90')
+ sys.path.append('C:/vault90/vault90')

i ran this and was getting the same error.

so i shut down the server and just ran the vault90 wsgi.py file and i found that it was breaking on the logging call i had set in the settings.py.

The server start up and everything was working fine. but I realized that which ever site I visit first is the one that loads correctly, and the other returns a wsgi no application error.

first land wins

90 first:

Error log vault90

	[Mon Jan 06 21:50:25.532782 2025] [wsgi:info] [pid 19064:tid 1264] [client 141.101.98.223:21510] mod_wsgi (pid=19064, process='', application='example.com|'): Loading Python script file 'C:/vault90/vault90/wsgi.py'.

Error Log tbg

	[Mon Jan 06 21:50:28.235599 2025] [wsgi:info] [pid 19064:tid 1244] [client 141.101.98.238:17850] mod_wsgi (pid=19064, process='', application='example2.com|'): Loading Python script file 'C:/tbg/tbg/wsgi.py'.
	[Mon Jan 06 21:50:28.454297 2025] [wsgi:error] [pid 19064:tid 1244] [client 141.101.98.238:17850] mod_wsgi (pid=19064): Target WSGI script 'C:/tbg/tbg/wsgi.py' does not contain WSGI application 'application'.
	[Mon Jan 06 21:50:30.284701 2025] [wsgi:error] [pid 19064:tid 1244] [client 141.101.98.238:17850] mod_wsgi (pid=19064): Target WSGI script 'C:/tbg/tbg/wsgi.py' does not contain WSGI application 'application'.

Other way around, tbg first:

Error Log tbg

	[Mon Jan 06 21:52:54.552160 2025] [wsgi:info] [pid 11068:tid 1280] [client 141.101.98.67:37198] mod_wsgi (pid=11068, process='', application='example2.com|'): Loading Python script file 'C:/tbg/tbg/wsgi.py'.

Error log vault90

	[Mon Jan 06 21:52:56.704988 2025] [wsgi:info] [pid 11068:tid 1276] [client 141.101.98.223:27390] mod_wsgi (pid=11068, process='', application='example.com|'): Loading Python script file 'C:/vault90/vault90/wsgi.py'.
	[Mon Jan 06 21:52:56.941081 2025] [wsgi:error] [pid 11068:tid 1276] [client 141.101.98.223:27390] mod_wsgi (pid=11068): Target WSGI script 'C:/vault90/vault90/wsgi.py' does not contain WSGI application 'application'.
	[Mon Jan 06 21:52:56.969155 2025] [wsgi:error] [pid 11068:tid 1276] [client 141.101.98.223:27390] mod_wsgi (pid=11068): Target WSGI script 'C:/vault90/vault90/wsgi.py' does not contain WSGI application 'application'.

Is this because i am setting up the same default os.environ.setdefault() setting in both WSGI files?

tbg/wsgi.py

import os
import sys
import logging
import traceback
from django.core.wsgi import get_wsgi_application

# Add your project directory to the sys.path
sys.path.append('C:/tbg')

# Set the settings module for the project
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tbg.settings')

# Setup logging for WSGI errors
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

try:
	# Get the WSGI application
	application = get_wsgi_application()
except Exception:
    logger.error('WSGI failed to start', exc_info=True)
    traceback.print_exc()

vault90 WSGI.py

import os
import sys
import logging
import traceback
from django.core.wsgi import get_wsgi_application

# Add your project directory to the sys.path
sys.path.append('C:/vault90')

# Set the settings module for the project
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vault90.settings')

# Setup logging for WSGI errors
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

try:
	# Get the WSGI application
	application = get_wsgi_application()
except Exception:
    logger.error('WSGI failed to start', exc_info=True)
    traceback.print_exc()

I am not an Apache expert, but I would think that is most likely related to how mod_wsgi is managing the WSGI application instances for different Django applications.

Most likely you need to configure Apache to run each application in its own daemon process.

What is your Apache configuration?

Also, this might help you: How to use Django with Apache and mod_wsgi | Django documentation | Django