最近来了兴致,想搞一下django开发,so,  搭建一下环境

1、安装django,可能通过pip install 或者源码安装(因为环境是python2.6.6的环境,所以这里采用django 1.4.17的版本):

 
# tar zxvf Django-1.4.17
# cd Django-1.4.17
# python setup.py install
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/bin/django-admin.py to 755
running install_data
running install_egg_info
Removing /usr/lib/python2.6/site-packages/Django-1.4.17-py2.6.egg-info
Writing /usr/lib/python2.6/site-packages/Django-1.4.17-py2.6.egg-info

因为之前安装了一次所以输出比较少

 
# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 4, 17, 'final', 0)

2、安装uwsgi。uwsgi是一个快速的,纯C语言开发的,自维护、对开发者友好的WSGI服务器,旨在提供专业的python web应用发布和开发功能

 
# tar zxvf uwsgi-2.0.9.tar.gz
# cd uwsgi-2.0.9
socket/plugin.o -lpthread -lm -rdynamic -ldl -lz -L/usr/local/lib -lpcre -lssl -lcrypto -lxml2 -lz -lm -lpthread -ldl -lutil -lm -lpython2.6 -lcrypt
################# uWSGI configuration ################# pcre = True
kernel = Linux
malloc = libc
execinfo = False
ifaddrs = True
ssl = True
zlib = True
locking = pthread_mutex
plugin_dir = .
timer = timerfd
yaml = embedded
json = False
filemonitor = inotify
routing = True
debug = False
capabilities = False
xml = libxml2
event = epoll ############## end of uWSGI configuration #############
total build time: 1 seconds
*** uWSGI is ready, launch it with ./uwsgi *** # cp uwsgi /usr/bin
# cd ..

如果在这个过程中遇到下面错误,可以执行yum remove pcre-devel 然后再执行:

 
c:undefined reference to `pcre_free_study'
collect2: ld returned 1 exit status
*** error linking uWSGI ***
make: *** [all] Error 1

也可以使用pip进行安装:

 
# pip install uwsgi
Requirement already satisfied (use --upgrade to upgrade): uwsgi in /usr/lib/python2.6/site-packages
Cleaning up...

3、nginx配置

nginx的安装,我们在这里就不讲了,经常做的工作,相必大家都会,下面看一下vhost的配置:

 
# cat localhost.conf
server{
listen 80;
server_name localhost;
location / {
uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;
uwsgi_param UWSGI_CHDIR /data/www/OMserverweb;
uwsgi_param UWSGI_SCRIPT django_wsgi;
access_log off;
}
location ^~ /static{
root /data/www/OMserverweb/OMserverweb;
}
location ~* ^.+.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
root /data/www/OMserverweb/OMserverweb/static;
access_log off;
}
}

4、配置uwsgi。创建uwsgi配置文件/data/nginx/config/uwsgi.ini,详细内容如下:

 
# cat uwsgi.ini
[uwsgi]
socket = 127.0.0.1:9090
master = true
pidfile = /var/run/uwsgi.pid
processes = 8
chdir = /data/www/OMserverweb
pythonpath = ..
profiler = true
memory-report=true
enable-threads=true
logdate=true
limit-as=6048
daemonize=/data/nginx/logs/django.log

进入到网站根目录/data/www:

 
# django-admin.py startproject OMserverweb
# tree
.
├── django_wsgi.py
├── django_wsgi.pyc
├── manage.py
└── OMserverweb
├── __init__.py
├── __init__.pyc
├── settings.py
├── settings.pyc
├── urls.py
├── urls.pyc
├── wsgi.py
└── wsgi.pyc

创建django_wsgi:

 
# cat django_wsgi.py
#!/usr/bin/env python
# coding: utf-8 import os
import sys # 将系统的编码设置为UTF8
reload(sys)
sys.setdefaultencoding('utf8') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "OMserverweb.settings") from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

5、启动:

 
# uwsgi --ini /data/nginx/conf/uwsgi.ini
# /etc/init.d/nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ] # ps aux | grep uwsgi
root 10159 0.0 0.3 156504 5920 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10160 0.0 0.9 221416 18228 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10161 0.0 0.9 221436 18208 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10162 0.0 0.9 221552 18344 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10163 0.0 0.9 221548 18364 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10164 0.0 0.9 221552 18300 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10165 0.0 0.7 215352 14252 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10166 0.0 0.9 221448 18224 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 10167 0.0 0.7 215352 14248 ? S 11:32 0:00 uwsgi --ini /data/nginx/conf/uwsgi.ini
root 29104 0.0 0.0 103240 864 pts/0 S+ 13:18 0:00 grep uwsgi

打开网页输入域名:

 
It worked!
Congratulations on your first Django-powered page. Of course, you haven't actually done any work yet. Here's what to do next:
If you plan to use a database, edit the DATABASES setting in OMserverweb/settings.py.
Start your first app by running python manage.py startapp [appname].
You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!

说明环境搭建成功

nginx+django+uwsgi的更多相关文章

  1. Nginx+Django+Uwsgi+php

    在FreeBSD结合Nginx和FastCGI简单配置Django和PHP  http://blog.chinaunix.net/uid-11131943-id-3031767.html Nginx+ ...

  2. 自动化运维web环境搭建:Nginx+Django+uwsgi

    参考资料: http://lovelace.blog.51cto.com/1028430/1600594 http://www.cnblogs.com/xiongpq/p/3381069.html 安 ...

  3. nginx+django+uwsgi+https 配置问题点

    - ssl 证书申请 申请域名的网站申请下载对应文件即可 - nginx  配置 https [root@VM_2_29_centos conf]# nginx -t nginx: [emerg] u ...

  4. 使用django UWSGI 出现 Bad Request (400)

    使用 Nginx + Django+UWSGI 部署机器时,一直出现 Debugging Apache/Django/WSGI Bad Bad Request (400) 错误 最后发现问题是 Dja ...

  5. Django+uwsgi+Nginx安装部署

    安装 安装Nginx Nginx是最流行的高性能HTTP服务器. 安装pcre: wget https://sourceforge.net/projects/pcre/files/pcre/8.37/ ...

  6. Nginx+PostgreSQL+Django+UWSGI搭建

    最近因为项目上的需要开始大量使用nginx,因此也想趁机将以前常用的django+apache的架构换成django+nginx.常见的 django webapp 部署方式采用FCGI 或 WSGI ...

  7. Nginx+Python+uwsgi+Django的web开发环境安装及配置

    Nginx+Python+uwsgi+Django的web开发环境安装及配置 nginx安装 nginx的安装这里就略过了... python安装 通常系统已经自带了,这里也略过 uwsgi安装 官网 ...

  8. 了解django部署(Django + Uwsgi + Nginx)

    首先了解下基本概念: 1 WSGI WSGI:全称是Web Server Gateway Interface,是python应用程序或者框架和web服务器之间的一种接口,被广泛接受.WSGI不是服务器 ...

  9. centos6.5安装nginx+python+uwsgi+django

    nginx+uwsgi+django环境部署及测试 默认系统自带的python2.6.6 第一步(安装setuptools) wget https://pypi.python.org/packages ...

随机推荐

  1. 【英语】Bingo口语笔记(84) - 惊讶的表达

  2. 模糊聚类算法(FCM)

    伴随着模糊集理论的形成.发展和深化,RusPini率先提出模糊划分的概念.以此为起点和基础,模糊聚类理论和方法迅速蓬勃发展起来.针对不同的应用,人们提出了很多模糊聚类算法,比较典型的有基于相似性关系和 ...

  3. [Luogu4169][Violet]天使玩偶/SJY摆棋子

    luogu 题意 一个平面上有\(n\)个点,\(m\)次操作,每次新增一个点,或者是询问离某个点最近的点的距离.这里的距离是曼哈顿距离. \(n,m\le3*10^5\) sol 写一发\(CDQ\ ...

  4. 使用pinyin4j汉字转pinyin

    引入maven依赖<dependencies> <dependency> <groupId>com.belerweb</groupId> <art ...

  5. 笔记:Why don't you pull up a chair and give this lifestyle a try?

    Why don't you pull up a chair and give this lifestyle a try? Why don't you pull up a chair and give ...

  6. ecmall允许上传的图片大小

    $uploader->allowed_type($type); $uploader->allowed_size($size);  ecmall上传类型大小是这样定义,你可以去文件中搜索相关 ...

  7. 主窗体上按钮jig画图时,CAD得不到焦点的问题

    主窗体上按钮jig画图时,CAD得不到焦点的问题    按钮不要用 Click 事件,用 MouseDown 事件, 可完美解决该问题 1.试过CAD窗体获得焦点,不顶用 2.试用用命令行去执行,可行 ...

  8. (转)oracle - type

    本文转载自:http://www.cnblogs.com/o-andy-o/archive/2012/05/25/2517741.html type定义: oracle中自定义数据类型oracle中有 ...

  9. Activity小技巧

    随时随地退出程序 新建一个结合类对所有活动进行管理. public class ActivityCollector{ public static List<Activity> activi ...

  10. 平台调用之如何利用VS2013 C#调试C++DLL库

    对于托管代码调用非托管DLL文件,已经是非常普遍的事情,下面写一下如何通过托管代码(C#)像调试托管代码一样调试DLL中的代码. 注意:(1)[dll工程和调用dll的exe工程需要在同一个解决方案中 ...