要將Django與Apache集成,可以使用mod_wsgi模塊。以下是配置步驟:
1. 安裝mod_wsgi:
pip install mod_wsgi
2. 在Apache配置文件中(通常是httpd.conf或apache2.conf),添加以下內(nèi)容:
LoadModule wsgi_module modules/mod_wsgi.so
3. 在配置文件中,為Django項(xiàng)目創(chuàng)建一個(gè)新的虛擬主機(jī)或站點(diǎn)配置:
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
WSGIScriptAlias / /path/to/your/django/project/wsgi.py
WSGIDaemonProcess yourdomain.com python-path=/path/to/your/django/project:/path/to/your/venv/lib/python3.x/site-packages
WSGIProcessGroup yourdomain.com
<Directory /path/to/your/django/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /path/to/your/django/project/static/
<Directory /path/to/your/django/project/static>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
4. 重啟Apache服務(wù)器以應(yīng)用更改:
sudo service apache2 restart
現(xiàn)在,Django應(yīng)用程序應(yīng)該可以通過(guò)Apache服務(wù)器訪問了。