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 |
-
open
vhosts
Configuration is loaded# httpd.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf Copy code
-
open
mod_proxy
andmod_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
-
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 :
-
This machine
python
downloadmod_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
-
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 -
modify
vhosts.conf
take Three lines of copied text Copied to the
vhosts.conf
Headthen 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
The sidebar is recommended
- Python * * packaging and unpacking details
- Python realizes weather query function
- Python from 0 to 1 (day 12) - Python data application 2 (STR function)
- Python from 0 to 1 (day 13) - Python data application 3
- Numpy common operations of Python data analysis series Chapter 8
- How to implement mockserver [Python version]
- Van * Python! Write an article and publish the script on multiple platforms
- Python data analysis - file reading
- Python data De duplication and missing value processing
- Python office automation - play with browser
guess what you like
-
Python series tutorial 127 -- Reference vs copy
-
Control flow in Python: break and continue
-
Teach you how to extract tables in PDF with Python
-
leetcode 889. Construct Binary Tree from Preorder and Postorder Traversal(python)
-
leetcode 1338. Reduce Array Size to The Half(python)
-
Object oriented and exception handling in Python
-
How to configure load balancing for Django service
-
How to embed Python in go
-
Python Matplotlib drawing graphics
-
Python object-oriented programming 05: concluding summary of classes and objects
Random recommended
- Python from 0 to 1 (day 14) - Python conditional judgment 1
- Several very interesting modules in Python
- How IOS developers learn Python Programming 15 - object oriented programming 1
- Daily python, Chapter 20, exception handling
- Understand the basis of Python collaboration in a few minutes
- [centos7] how to install and use Python under Linux
- leetcode 1130. Minimum Cost Tree From Leaf Values(python)
- leetcode 1433. Check If a String Can Break Another String(python)
- Python Matplotlib drawing 3D graphics
- Talk about deep and shallow copying in Python
- Python crawler series - network requests
- Python thread 01 understanding thread
- Analysis of earthquake distribution in the past 10 years with Python~
- You need to master these before learning Python crawlers
- After the old friend (R & D post) was laid off, I wanted to join the snack bar. I collected some data in Python. It's more or less a intention
- Python uses redis
- Python crawler - ETF fund acquisition
- Detailed tutorial on Python operation Tencent object storage (COS)
- [Python] comparison of list, tuple, array and bidirectional queue methods
- Go Python 3 usage and pit Prevention Guide
- Python logging log error and exception exception callback method
- Learn Python quickly and take a shortcut~
- Python from 0 to 1 (day 15) - Python conditional judgment 2
- Python crawler actual combat, requests module, python to capture headlines and take beautiful pictures
- The whole activity collected 8 proxy IP sites to pave the way for the python proxy pool, and the 15th of 120 crawlers
- Why can't list be used as dictionary key value in Python
- Python from 0 to 1 (day 16) - Python conditional judgment 3
- What is the python programming language?
- Python crawler reverse webpack, a real estate management platform login password parameter encryption logic
- Python crawler reverse, a college entrance examination volunteer filling platform encrypts the parameter signsafe and decrypts the returned results
- Python simulated Login, selenium module, python identification graphic verification code to realize automatic login
- Python -- datetime (timedelta class)
- Python's five strange skills will bring you a sense of enrichment in mastering efficient programming skills
- [Python] comparison of dictionary dict, defaultdict and orderdict
- Test driven development using Django
- Face recognition practice: face recognition using Python opencv and deep learning
- leetcode 1610. Maximum Number of Visible Points(python)
- Python thread 03 thread synchronization
- Introduction and internal principles of Python's widely used concurrent processing Library Futures
- Python - progress bar artifact tqdm usage