SoFunction
Updated on 2024-10-29

Apache deployment Django project graphic details

preamble

Django project itself can start running, why do you need to deploy to Apache or Nginx? Beginners will encounter this problem, let's take a look at the official explanation: It's intended only for use while developing. (We're in the business of making Web frameworks, not Web servers.), meaning that django's business is to (We're in the business of making Web frameworks, not Web servers. Comes with a web server just to facilitate the development, and can not be put directly into the production environment, interested students can test their own performance gap between the two. Back to business, we are here to talk about how to build Apache environment.

Installing Apache

Apache (win 64) download:/cgi-bin/#APACHE24VC09

1. Unzip and modify the apache path and port in the Apache24\conf\ file:

......
Define SRVROOT "E:/Apache24"  
ServerRoot "${SRVROOT}"
......

#Listen 12.34.56.78:80
Listen 8088
......

ServerName localhost:8088
......

2. Open E:\Apache24\bin\, in the browser enter http://127.0.0.1:8088/ Welcome page appears on behalf of success.

mod_wsgi module download:/~gohlke/pythonlibs/#mod_wsgi

1. Change the whl file to zip, unzip it, copy the mod_wsgi.so inside to E:\Apache24\modules path, and add a new paragraph in the configuration:

# Add mod_wsgi.so module
LoadModule wsgi_module modules/mod_wsgi.so 

If mod_wsgi can not find mod_wsgi.so file after unpacking (skip this step if you have)

Run cmd and go to the Scripts directory to perform the installation:

pip3 install mod_wsgi-4.5.17+ap24vc10-cp34-cp34m-win_amd64.whl

Execute: mod_wsgi-express module-config in the Scripts directory.

Copy the three lines to:

# Add mod_wsgi.so module
LoadFile "c:/python34/DLLs/"
LoadModule wsgi_module "c:/python34/lib/site-packages/mod_wsgi/server/mod_wsgi.pyd"
WSGIPythonHome "c:/python34"

Configuring Apache with Django

1. Open the Apache configuration file and add a configuration paragraph at the end:

# Add mod_wsgi.so module
LoadFile "c:/python34/DLLs/"
LoadModule wsgi_module "c:/python34/lib/site-packages/mod_wsgi/server/mod_wsgi.pyd"
WSGIPythonHome "c:/python34"
 
# Specify the path to the configuration file for the myweb project
WSGIScriptAlias / D:/mysite/mysite/ 
 
# Specify the project path
WSGIPythonPath D:/mysite 
 
<Directory D:/mysite/mysite> 
<Files > 
  Require all granted 
</Files> 
</Directory> 
 
Alias /static D:/mysite/static  
<Directory D:/mysite/static>  
  AllowOverride None 
  Options None 
  Require all granted 
</Directory>

2. Open the django project setting configuration:

DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1','localhost'] #accessibleip。It is also possible to use'*'indicate,Unrestricted representation

Restart bin\, enter URL

Test OK.

3. Install Apache as a windows server, you do not need to open every time a small black box appears.

Run the cmd command httpd -k install -n "service name" in the bin directory (without parameters, defaults to Apache 2.4)

Run apache: net start apache2.4

Stop apache: net stop apache2.4

Delete apache: sc delete Apache2.4

This is the whole content of this article.