1.安装Apache2:html
sudo apt-get install apache2
2.安装 mod_wsgiweb
# Python 3 sudo apt-get install libapache2-mod-wsgi-py3
3.确认安装apache的版本号:数据库
apachectl -v
显示:2.4.18,ok了apache
4.将mod-wsgi添加到apache的配置文件中:服务器
vi /etc/apache2/apache2.conf
执行该命令,打开apache的配置文件,而且将mod添加到配置文件post
在末尾添加这几行测试
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so #Server Name ServerName 127.0.0.1
5.配置网站的Django项目目录及配置网站
执行下面命令,其中红色部分,能够本身设置为项目的名称,最好统一。ui
vi /etc/apache2/sites-available/website.conf
注意:1.若是没有域名和公网ip,是部署在虚拟机中,直接用虚拟机的ip地址(ifconfig能够查看到)来代替 ServerName 和 ServerAlias 后面的内容。以下面红色部分所示.url
2. /var/www/website :该地址为你的项目网站地址
<VirtualHost *:80> ServerName 192.168.0.10 ServerAlias 192.168.0.10 ServerAdmin abc@qq.com <Directory /var/www/website> Require all granted </Directory> WSGIScriptAlias / /var/www/website/website/wsgi.py <Directory /var/www/website/website> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost>
6.激活配置:
执行命令:
a2ensite website.conf
执行命令:
service apache2 reload
到这里,apache服务器基本完成。