Environment:
Debian8
apache2.4.10 #请注意自己的apache版本, different versions of configuration file structure vary greatly
django1.10
python3.4
The default apache2 is already installed
Django Project Path/var/www/mysite
---------------------------------------------------------------------------------------------------
Install Mod_wsgi First
Install libapache2-mod-wsgi-py3 #python3aptinstall libapache2-mod-wsgi # Python2
Create a Django Project
cd/var/Wwwdjango-admin startproject mysitecd mysitemkdir staticCP -R/ Usr/local/lib/python3. 4/dist-packages/django/contrib/admin/static/* ./static/ #复制后台样式文件到项目目录
Create a virtual host configuration file
cd/etc/apache2/sites-enabled/CP the-default.conf001-Default.confnano001-default.conf
<virtualhost *:Bayi>ServerAdmin [email protected] documentroot/var/www/mysite errorlog ${apache_log_dir}/error.log customlog ${apache_log_dir}/Access.log Combined # Store user upload pictures and other files location Alias/media//var/www/mysite/media/# static file (JS/css/images) storage location Alias/static//var/www/mysite/static/# allows static content to be fetched over the network<Directory/var/www/mysite/static/>Require All granted</Directory># The most important! Let Apache recognize this as a Django project by wsgi.py, don't miss out on the front/Wsgiscriptalias//var/www/mysite/mysite/wsgi.py # wsgi.py file's parent directory<Directory/var/www/mysite/mysite/> <files wsgi.py>Require All granted</Files> </Directory> </VirtualHost># Vim:syntax=apache ts=4sw=4sts=4SR Noet
Edit/etc/apache2/ports.conf Add a row Listen Bayi #监听81端口, is our new virtual host
Edit/etc/apache2/mods-enabled/wsgi.load
LoadModule wsgi_module/usr/lib/apache2/modules/mod_wsgi.so-3.4 /usr/lib/apache2/modules/ mod_wsgi.so #python2
Edit/etc/apache2/mods-enabled/wsgi.conf
Add a row Wsgipythonpath/var/www/mysite #项目所在路径
This time, it's almost over. Can service apache2 start
Visit: 127.0.0.1:81
It worked! Congratulations on your first django-powered page.
Visit: 127.0.0.1:81/admin will error
Initializing the database file
manage.py Migrate
Ok!
If you are deploying on a virtual machine or remote host do not forget to modify allowed_hosts = [] in settings.py, add an accessible domain name or IP list
Apache2 Deploying Django