I want to deploy my Django project using Apache and WSGI, Windows. I tried everything on net, installed Apache, download visual studio builder, install pip install mod_wsgi, modified httpd.conf & httpd.conf… etc. I can can start Apache sucessfully but still my-site.com not reachable! I think I am missing something.
Maybe can someone help me , thanks a lot
‘’’
#httpd-vhosts
<VirtualHost *:80>
ServerName my-site.com
DocumentRoot "C:/my-django-project"
<Directory "C:/my-django-project">
Require all granted
</Directory>
WSGIScriptAlias / "C:/my-django-project/wsgi.py"
# Additional directives as needed
'''
I used this code, it calls my script properly:
httpd.conf
WSGIPythonHome "C:/Program Files/Python312"
WSGIPythonPath "C:/Program Files/Python312/Lib/site-packages"
LoadFile "C:/Program Files/Python312/python312.dll"
LoadModule wsgi_module "C:/Program Files/Python312/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp312-win_amd64.pyd"
extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost:80
WSGIPassAuthorization On
ErrorLog "C:/Users/felhasznalo/Desktop/django/todo.error.log"
CustomLog "C:/Users/felhasznalo/Desktop/django/todo.access.log" combined
WSGIScriptAlias / "C:/Users/felhasznalo/Desktop/django/todo/wsgi_windows.py"
WSGIApplicationGroup %{GLOBAL}
DocumentRoot "C:/Users/felhasznalo/Desktop/django/todo"
<Directory "C:/Users/felhasznalo/Desktop/django/todo">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/Users/Administrator/Desktop/django/todo/static"
<Directory "C:/Users/Administrator/Desktop/django/todo/static">
Require all granted
</Directory>
</VirtualHost>
environment variables
MOD_WSGI_APACHE_ROOTDIR
C:\wamp64\bin\apache\apache2.4.54.2\
wsgi_windows.py
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
I am not sure what is really necessary for the upper code to work, but it works on Windows 10. As of Django, I did not manage to configure it so far, but this plain simple hello world app works, so the problem is with Django WSGI, not with the server in my case. Happy coding!
I managed to configure it meanwhile. Somehow the DJANGO_SETTINGS_MODULE
environment variable is not read by Django, but it is possible to configure it using the django.conf
module.
from django.conf import settings
from django.core.wsgi import get_wsgi_application
import app.settings as app_settings
for key,value in app_settings.__dict__.items():
setattr(settings, key, value)
application = get_wsgi_application()