搬瓦工ubuntu 14.04 x86环境配置(apache2、mod_wsgi)

参考网站:

http://code.ziqiangxuetang.com/django/django-deploy.html

http://www.jianshu.com/p/ff78d1ab5091

 

1、进入ubuntu,安装apache2和mod_wsgi:
apt-get install apache2 libapache2-mod-wsgi-py3
2、查看apache2版本:
apachectl -v
3、新建一个网站,这里是创建一个网站的配置文件

nano /etc/apache2/sites-available/test1.conf

<VirtualHost *:80>
    ServerName www.yourdomain.com
    ServerAlias otherdomain.com
    ServerAdmin tuweizhong@163.com
 
    Alias /media/ /home/tu/blog/media/
    Alias /static/ /home/tu/blog/static/
 
    <Directory /home/tu/blog/media>
        Require all granted
    </Directory>
 
    <Directory /home/tu/blog/static>
        Require all granted
    </Directory>
 
    WSGIScriptAlias / /home/tu/blog/blog/wsgi.py
    # WSGIDaemonProcess ziqiangxuetang.com pythonpath=/home/tu/blog:/home/tu/.virtualenvs/blog/lib/python2.7/site-packages
    # WSGIProcessGroup ziqiangxuetang.com
 
    <Directory /home/tu/blog/blog>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>
</VirtualHost>

4、修改wsgi文件,

import os
from os.path import join,dirname,abspath
PROJECT_DIR = dirname(dirname(abspath(__file__)))#3
import sys # 4
sys.path.insert(0,PROJECT_DIR) # 5
os.environ["DJANGO_SETTINGS_MODULE"= "blog.settings" # 7
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

5、启用apache2配置文件
service apache2 reload 
a2dissite 000-default && a2ensite sitename.conf
service apache2 restart

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注