Gentoo下搭建Django环境

在gentoo下搭建Django环境还是很方便的,首先当然得配好Web Server啦,我用的是Nginx,因为我们使用FastCgi,所以我们还需要安全Flup和Django

可能有些人还不清楚Nginx, Flup和Django的关系,其实这个关系和Nginx, Spawn-fcgi和php-cgi的关系是一样的,Flup是一个WSGI Server

1、安装配置Nginx(略去)

2、安装Flup、Django

emerge flup django

3、配置和测试Django
cd ~
django-admin.py startproject www
cd www
python manage.py runserver 127.0.0.1:8000

4、配置Flup
在/etc/init.d/增加django服务脚本
#!/sbin/runscript
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

depend() {

return

}

start() {

/usr/bin/python2.6 /root/www/manage.py runfcgi method=threaded host=localhost port=8000

}

stop() {

kill -9 ps ax | grep '/root/www/manage.py' | grep -v grep | awk -F' ' '{print $1}'

}

restart() {

svc_stop

svc_start

}
别忘记

rc-update add django default

5、配置Nginx.conf
location /django {
fastcgi_pass 127.0.0.1:8000;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_intercept_errors off;
}

6、最终测试
/etc/init.d/nginx restart
/etc/init.d/django restart

访问http://xxx/django就可以看到测试页面啦

0%