Configuration
- python: 3.6.3
- django: 2.0.1
- ubuntu: 17.10
Deploy django step by step
- VirtualHost
vim /etc/apache2/sites-available/sitename.conf
<VirtualHost *:80>
ServerName 10.245.36.112
ServerAlias localhost
ServerAdmin hans@xxx.com
Alias /static/ /var/www/my/static/
<Directory /var/www/my/static>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/my/my/wsgi.py
<Directory /var/www/my/my>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
- wsgi.py
vim /var/www/my/my/wsgi.py
import os,sys
from django.core.wsgi import get_wsgi_application
from os.path import join,dirname,abspath
PROJECT_DIR = dirname(dirname(abspath(__file__)))
sys.path.insert(0,PROJECT_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my.settings")
application = get_wsgi_application()
- enable sitename.conf and apache2
a2ensite sitename.conf
a2dissite sitename.conf
systemctl reload apache2
- Test
![这里写图片描述](https://img-blog.csdn.net/20180116201647412?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd29uZGVydmljdG9y/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)