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/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
     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]
        ServerName www.test.com
        ServerAlias www.test.com test.com #  Website alias   It can be the domain name of the old website 
        ProxyPass "/foo/" "http://192.168.1.xxx:8080/"  #  take  www.test.com/foo/a  Of   Request forwarding   To  192.168.1.xxx:8080/a
        ProxyPassReverse "/foo/"  "http://192.168.1.xxx:3080"  #  take  www.test.com/foo/a  Proxy to  192.168.1.xxx:8080/a
        
        Alias /static "${PROJECT_DIR}/static"  #  Static file directory access 
        #  jurisdiction   Set up 
        <Directory "${PROJECT_DIR}/static">
            <RequireAll>
                Require all granted
            </RequireAll>
        </Directory>
        #  Log Settings   One file a day 
        SetEnvIf Request_URI "\.(gif|jpg|png|css|js)$" static_request
        ErrorLog "|bin/rotatelogs.exe logs/error-qitay.com-%Y%m%d.log 86400 480" #  Error log  apaache  There is a default log format 
        CustomLog "|bin/rotatelogs.exe logs/access-demo.com-%Y%m%d.log 86400 480" common env=!static_request  # env=!static_request  Do not log access to static files 
        CustomLog "|bin/rotatelogs.exe logs/details-demo.com-%Y%m%d.log 86400 480" combined  # combined  Is in  httpd  As defined in the document   Log format 
    </VirtualHost>
     # second VirtualHost
    
    <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName test.test.com
        ServerAlias test.test.com
        ProxyPass "/foo/" "http://192.168.1.xxx:8080/"
    </VirtualHost>
     Copy code 

django Project configuration

# httpd-vhosts.conf
 #  In the machine python  Installation in environment  pip install mod_swgi -r https://pypi.douban.com/simple
#  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]
    ServerName www.demo.com
    ServerAlias www.demo.com
    DocumentRoot "${DJANGO_PROJECT}" #  Site root 

    # log
    SetEnvIf Request_URI "\.(gif|jpg|png|css|js)$" static_request
    ErrorLog "|bin/rotatelogs.exe logs/error-qitay.com-%Y%m%d.log 86400 480"
    CustomLog "|bin/rotatelogs.exe logs/access-demo.com-%Y%m%d.log 86400 480" common env=!static_request 
    CustomLog "|bin/rotatelogs.exe logs/details-demo.com-%Y%m%d.log 86400 480" combined
    WSGIScriptAlias / "${DJANGO_PROJECT}/dj_demo/wsgi.py"
    # dj_demo wsgi.py  File permissions for 
   <Directory "${DJANGO_PROJECT}/dj_demo">
        <Files wsgi.py>
            <RequireAll>
                Require all granted
            </RequireAll>
        </Files>
   </Directory>

    #  Set static file path 
    Alias /static "${DJANGO_PROJECT}/static"
    #  Static file permissions 
   <Directory "${DJANGO_PROJECT}/static">
        <RequireAll>
            Require all granted
        </RequireAll>
   </Directory>
 Copy code 
# dj_demo/wsgi.py 
#  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 https://pypi.douban.com/simple

    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 https://pypi.douban.com/simple

    change Project wsgi.py 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.
https://en.pythonmana.com/2022/02/202202011041336064.html

Random recommended