您的位置:首页 > 运维架构 > Apache

Deploy Django in Apache in Ubuntu 17.10

2017-12-19 17:20 316 查看

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
#ServerName localhost
#ServerAlias 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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: