This is a basic web app to illustrate deployment on Microsoft IIS, Apache + mod_wsgi, or nginx
- Watch on YouTube: Deploy Django on Windows using Microsoft IIS
-
Install IIS on your VM or machine, and enable CGI
-
Copy
webprojecttoC:/inetpub/wwwroot/webproject -
Install Python 3.7 in
C:/Python37, and install the necessary librariesdjango,openpyxl,wfastcgi; seewebproject/install_requirements.bat -
Navigate to
C:/, right-click onPython37, and editProperties. Under Security, addIIS AppPool\DefaultAppPool.DefaultAppPoolis the default app pool. -
Enable wfastcgi
-
Open a CMD terminal as Administrator, and run the command
wfastcgi-enable. -
Copy the Python path, and replace the
scriptProcessor="<to be filled in>"in web-config-template with the Python path returned bywfastcgi-enable.
-
-
Edit the remaining settings in
web-config-templatethen save it asweb.configin theC:/inetpub/wwwroot/directory. It should NOT sit insidewebproject/. Other settings can be modified ifwebprojectdoes NOT sit atC:/inetpub/wwwroot/-
Edit project
PYTHONPATH(path to your project) -
Edit
WSGI_HANDLER(located in yourwsgi.py) -
Edit
DJANGO_SETTINGS_MODULE(yoursettings.pymodule)
-
-
Open Internet Information Services (IIS) Manager. Under connections select the server, then in the center pane under Management select Configuration Editor. Under Section select system.webServer/handlers. Under Section select Unlock Section. This is required because the
C:/inetpub/wwwroot/web.configcreates a route handler for our project. -
Add Virtual Directory. In order to enable serving static files map a static alias to the static directory,
C:/inetpub/wwwroot/webproject/static/ -
Refresh the server and navigate to
localhost
- Watch on YouTube: Deploy Django with Apache and mod_wsgi on Windows Server 2019
For Apache 2.4 and mod_wsgi use the httpd.conf.template
-
Download and install Apache 2.4 in
C:/Apache24. Use Apache Lounge, or any flavor you prefer.-
After copying files over to
C:/Apache24, open a CMD terminal as Administrator. Navigate toC:/Apache24and runbin\httpd.exe -k installto install the Apache service. You can then navigate tolocalhostto view the test page. -
You can start the service by running
httpd.exe -k start -
You can stop the services by running
httpd.exe -k stopand restart it byhttpd.exe -k restart
-
-
Install Microsoft C++ Build Tools. You will need this before you run
pip install mod_wsgi. -
Install Python 3.7 in
C:/Python37(you don't need to create a virtual environment) -
Install
django,openpyxl,modwsgi(seeinstall_requirements.bat) -
On a CMD terminal, run
mod_wsgi-express module-config, then copy the contents and editwebproject/httpd.conf.template. Edit paths to Python and your Django project. -
On a CMD terminal, run
C:/Apache24/bin/httpd.exe -k start, open a web browser and navigate tolocalhost(make sureALLOWED_HOSTShas been updated).
For Microsoft IIS please use the webproject/web-config-template and the webproject/static/web.config files. Update the web-config-template as needed. It will be used to create a web.config that sits on C:/inetpub/wwwroot/web.config; The directory will contain all project files: C:/inetpub/wwwroot/web.config along with C:/inetpub/wwwroot/webproject.
- Watch on YouTube: Deploy Django with NGINX and Waitress on Windows Server 2019
-
Download and copy nginx to
C:/. -
Install Python 3.7 in
C:/Python37and installdjango,openpyxlandwaitress
-
Edit
ALLOWED_HOSTSinsettings.py. Waitress will be running the Django server athttp://localhost:8080. -
Collect static files by running
python manage.py collectstatic -
Edit
nginx_waitress/webproeject_nginx.conf-
Edit the
server_name -
Edit the path to
/static(and/mediaif needed) -
Edit
proxy_passto match the server running from Waitress (i.e.runserver.py). This will usually belocalhostor your IP address
-
-
Create two directories inside of
C:/nginx/-
Create
sites-enabledandsites-available -
Copy
webproject_nginx.confto the two directories
-
-
Edit
C:/nginx/conf/nginx.conf-
Add
include <path to your sites-enabled/webproject_nginx.conf>; -
Change port
80to a non-essential port like10. We will need to utilize80for our Django project
-
-
Open a terminal at
C:/nginx/and runnginx.exe -tto check files, and if everything is successful runnginx.exeto start the server -
Open a web browser and navigate to
http://localhost