Ubuntu Apache下部署Dja

发布时间:2019-10-15 09:04:54编辑:auto阅读(2350)

    环境

    • ubuntu:18.04
    • Apache:2.4.29
    • Python:3.6.6
    • Django:2.1.3

    Python

    系统自带Python2.7.15rc以及Python3.6.6

    安装Apache

    sudo apt install apache2
    sudo apt install libapache2-mod-wsgi-py3

    安装Django

    体验Django2,就必须要求是Python3,所以下面都是基于Python3

    安装pip

    sudo apt install python3-pip

    安装Django2

    sudo pip3 install django
    这里一定要使用sudo,否则,Apache无法import django

    修改Apache

    文件路劲: /etc/apache2/sites-available/000-default.conf
    <VirtualHost *:80>
        ServerName www.example.com
        ServerAlias example.com
        ServerAdmin example@126.com
      
        #Alias /media/ /home/blog/media/
        #Alias /static/ /home/blog/static/
      
        #<Directory /home/blog/media>
        #    Require all granted
        #</Directory>
      
        #<Directory /home/blog/static>
        #    Require all granted
        #</Directory>
      
        WSGIScriptAlias / /home/blog/blog/wsgi.py
      
        <Directory /home/blog/geek>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    </VirtualHost>
    

    重启Apache

    sudo service apache2 restart

关键字