sudo apt-get install apache2
sudo apt-get install apache2-dev
sudo apt-get install python3-dev
sudo apt-get install libapache2-mod-wsgi-py3
apache2配置文件夹
/etc/apache2/
mod_wsgi官方文档
更新mod_wsgi
https://github.com/GrahamDumpleton/mod_wsgi/releases
下载文件,解压,根据官方文档进行安装。
ls /etc/apache2/mods-enabled/
查看目录下是否有wsgi.conf文件
和a2enmod wsgi
命令来查看wsgi是否启动
配置
vim /etc/apache2/sites-available/projectname.conf
projectname.conf
<VirtualHost *:80>
# 开放静态目录
Alias /static/ /path/to/project/static/
<Directory /path/static>
Require all granted
</Directory>
#开放上传文件夹
Alias /media/ /path/to/media/
<Directory /path/media>
Require all granted
</Directory>
#虚拟环境
Alias /favicon.ico /project/favicon.ico
<Directory /projectpath>
<Files favicon.ico>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess projectname python-home=/venv path python-path=/project path
WSGIProcessGroup projectname
#无虚拟环境
WSGIScriptAlias / /your project path/wsgi.py
<Directory /your project path>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
查看虚拟环境的目录,进入虚拟环境,
命令python -c 'import sys; print(sys.prefix)'
开启服务
/etc/apache2/site-available/
a2ensite projectname.conf
#停止服务
a2dissite
service apache2 reload
关闭默认 a2dissite 000-default.conf
查看配置是否有问题apache2ctl configtest
重启服务
apache2ctl restart
查看错误日记
cat /var/log/apache2/error.log
番外
django
settings.py
设置静态文件根目录
STATIC_ROOT = os.path.join(BASE_DIR, 'setcollectiondir')
这个目录用来python3 manage.py collectstatic 收集静态文件的
还有一个,要给media/ 777权限
chmod 777 media/