current position:Home>apache2. 4 + windows deployment Django (multi site)

apache2. 4 + windows deployment Django (multi site)

2022-02-01 10:41:34 BGLB

apache2.4 + windows Deploy Django

apache2.4 Multi site deployment

Virtual sites , Multi site Deploy django

File name File path Notes to the document
httpd.conf C:\Apache24\conf\httpd.conf apache Master profile Load module Listening port To configure serverName( must )
httpd-vhosts.conf C:\Apache24\conf\extra\httpd-vhosts.conf Multisite profile
httpd.exe C:\Apache24\bin\httpd.exe apache Start the service httpd -k start | stop | restart
  1. open vhosts Configuration is loaded

    # httpd.conf
    # Virtual hosts
    Include conf/extra/httpd-vhosts.conf
     Copy code 
  2. open mod_proxy and mod_proxy_http Module loading ( Modules to be used in reverse proxy )

    # httpd.conf
    LoadModule proxy_module modules/
    LoadModule proxy_http_module modules/
     Copy code 
  3. edit httpd-vhosts.conf To configure

    # # for further details before you try to setup virtual hosts.
    # You may use the command line option '-S' to verify your virtual host
    # configuration.
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for all requests that do not
    # match a ServerName or ServerAlias in any <VirtualHost> block.
    # # first VirtualHost
    <VirtualHost *:80>
    	Define PROJECT_DIR "E:/www/project_root/"  #  It is suggested to define a   Project home directory  |  Site root   Easy to use at the back 
        ServerAdmin [email protected]
        ServerAlias #  Website alias   It can be the domain name of the old website 
        ProxyPass "/foo/" ""  #  take  Of   Request forwarding   To
        ProxyPassReverse "/foo/"  ""  #  take  Proxy to
        Alias /static "${PROJECT_DIR}/static"  #  Static file directory access 
        #  jurisdiction   Set up 
        <Directory "${PROJECT_DIR}/static">
                Require all granted
        #  Log Settings   One file a day 
        SetEnvIf Request_URI "\.(gif|jpg|png|css|js)$" static_request
        ErrorLog "|bin/rotatelogs.exe logs/ 86400 480" #  Error log  apaache  There is a default log format 
        CustomLog "|bin/rotatelogs.exe logs/ 86400 480" common env=!static_request  # env=!static_request  Do not log access to static files 
        CustomLog "|bin/rotatelogs.exe logs/ 86400 480" combined  # combined  Is in  httpd  As defined in the document   Log format 
     # second VirtualHost
    <VirtualHost *:80>
        ServerAdmin [email protected]
        ProxyPass "/foo/" ""
     Copy code 

django Project configuration

# httpd-vhosts.conf
 #  In the machine python  Installation in environment  pip install mod_swgi -r
#  function  `mod_wsgi-express module-config`  Output the following three lines  
LoadFile "C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python37.dll"
LoadModule wsgi_module "C:/Users/Administrator/AppData/Local/Programs/Python/Python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "C:/Users/Administrator/AppData/Local/Programs/Python/Python37"  
<VirtualHost *:80> 
    Define DJANGO_PROJECT "E:/development/online/server/dj_demo"
    ServerAdmin [email protected]
    DocumentRoot "${DJANGO_PROJECT}" #  Site root 

    # log
    SetEnvIf Request_URI "\.(gif|jpg|png|css|js)$" static_request
    ErrorLog "|bin/rotatelogs.exe logs/ 86400 480"
    CustomLog "|bin/rotatelogs.exe logs/ 86400 480" common env=!static_request 
    CustomLog "|bin/rotatelogs.exe logs/ 86400 480" combined
    WSGIScriptAlias / "${DJANGO_PROJECT}/dj_demo/"
    # dj_demo  File permissions for 
   <Directory "${DJANGO_PROJECT}/dj_demo">
                Require all granted

    #  Set static file path 
    Alias /static "${DJANGO_PROJECT}/static"
    #  Static file permissions 
   <Directory "${DJANGO_PROJECT}/static">
            Require all granted
 Copy code 
# dj_demo/ 
#  Virtual environment deployment   If it's not a virtual environment   There is no need to change 
#  This is a reference to a blog , Blog links   Can not find .... 

import os
import sys
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, PROJECT_DIR)  #  Add the project to the guide package path 
virtualenv_dir = os.path.join(PROJECT_DIR, 'env', 'Lib', 'site-packages')  #  A virtual environment python Package folder 
sys.path.insert(0, virtualenv_dir)  #  Add the guide package path 

from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Qitai.settings')

application = get_wsgi_application()

 Copy code 

The deployment process is roughly divided into three steps :

  1. This machine python download mod_swgi

    pip install mod_swgi -i

    function mod_wsgi-express module-config

    Three lines of text to be output Copy Waiting to use

  2. Establish the virtual environment of the project

    cd {PROJECT_DIR} && python -m venv env

    pip install -r requirement.txt -i

    change Project file

  3. modify vhosts.conf

    take Three lines of copied text Copied to the vhosts.conf Head

    then Copy and paste the above configuration

    modify DJANGO_PROJECT ServerName ServerAlias

    It is necessary to word modify port

Only this and nothing more django project Deployment completed

Be careful First step download mod_swgi It only needs to be done once If you need to publish multiple django Website , Just start with the second step

copyright notice
author[BGLB],Please bring the original link to reprint, thank you.

Random recommended