網站架設:Ubuntu:Django + apache
阿新 • • 發佈:2021-02-14
qq:1132759952
1、 安裝適合python3版本的django
pip3 install django
2、檢視django庫安裝位置
pip3 show django
顯示如下:
3、建立專案
django-admin startproject mysites
python3 manage.py startapp index
4、安裝apache2
sudo apt install apache2
5、啟動apache2
/etc/init.d/apache2 start
6、安裝wsgi
apt install libapache2-mod-wsgi-py3
7、重新安裝mod-wsgi.so
安裝apache2開發包
apt install apache2-dev
在官網上找到wsgi原始碼連結並下載
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.7.1.tar.gz
解壓下載檔案
tar xvfz 4.7.1.tar.gz
進入壓縮後的檔案
cd mod_wsgi-4.7.1/
配置原始碼 (需要查詢apxs,python3位置)
whereis apxs
whereis python3
apt install python3.7-dev
./configure --with-apxs=/usr/bin/apxs --with-python=/usr/bin/python3.7
安裝mod-wsgi.so
make
make install
8、上阿里雲新增埠
網路與安全-安全組-配置規則
9、配置apache2的網站檔案
a2ensite mysite.conf
檔案內容如下:
ServerName 127.0.0.1:80 WSGIDaemonProcess mysites python-path=/home/mysites WSGIProcessGroup mysites WSGIScriptAlias / /home/mysites/mysites/wsgi.py <Directory /home/mysites/mysites> <Files wsgi.py> Require all granted </Files> </Directory>
10、將django專案中的setting.py
中的配置改為
ALLOWED_HOSTS = ['*']
11、更改wsgi.py
內容如下:
#sys.path.append("/usr/local/lib/python3.6/dist-packages")
#!/usr/bin/python3
import os,sys
sys.path.append("/usr/local/lib/python3.6/dist-packages")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysites.settings')
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/html/safe')
application = get_wsgi_application()
12、
遇到問題在
/var/log/apache2
中檢視