首页 > 代码库 > ubuntu14.04+Django1.7.1+nginx1.6+uwsgi2.0环境搭建
ubuntu14.04+Django1.7.1+nginx1.6+uwsgi2.0环境搭建
ubuntu下安装django1.7.1先安装pip
sudo apt-get install pip
使用pip安装django
sudo pip install Django
(或者下载官方最新的django包,解压后执行sudo python setup.py install)
安装完成后进入python 命令行校验django是否安装成功(或直接执行python -c "import django;print(django.get_version())")
>>> import django >>> print(django.get_version()) 1.7
安装mysql支持:
sudo apt-get install mysql-server
sudo apt-get install python-mysqldb
创建django项目
django-admin.py startproject mysite
创建一个项目的app,一般一个项目可能会有多个webapp
cd mysite
python manage.py startapp webapp
运行django自带轻量级服务器
python manage.py runserver 0.0.0.0:8000(ip和端口可以自定义)
安装nginx
sudo apt-get install nginx
安装uwsgi
sudo apt-get install python-dev
sudo pip install uwsgi
配置nginx.conf文件
upstream django{
server 127.0.0.1:8001;
}
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root /home/yyx/mysite;
uwsgi_pass django;
include uwsgi_params;
#index index.html index.htm;
}
location /static {
alias /home/yyx/mysite/webapp/static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
重新启动nginx
nginx -s reload
mysite/webapp目录下添加jango.xml,内容为
<uwsgi>
<socket>127.0.0.1:8001</socket>
<chdir>/home/yyx/mysite</chdir>
<pythonpath>./mysite</pythonpath>
<processes>10</processes>
<master>true</master>
<module>wsgi</module>
</uwsgi>
启动uwsgi
uwsgi -x /home/yyx/mysite/webapp/django.xml --plugins python
OK
ubuntu14.04+Django1.7.1+nginx1.6+uwsgi2.0环境搭建