CentOS+Python+Django+Flup+Nginx+PHP+PHP-FPM 搭建配置

make install easy_install setuptools
903 easy_install -U setuptools
908 easy_install django-tinymce
909 python manage.py runserver
910 yum install python-imaging
911 python manage.py runserver

python manage.py runfcgi method=prefork host=127.0.0.1 port=9001

参考:

http://blog.sina.com.cn/s/blog_54447c900100kdg5.html

Python和Django的安装就不写了,网上太多了,Django的部分推荐看http://www.djangoproject.com/ 已经很详细了。
下面记录一下怎样为Django配置Nginx:
需要用到flup,直接python setup.py install安装即可。http://trac.saddi.com/flup
然后
#python manage.py runfcgi socket=/tmp/python/python.sock maxrequests=1
当然也可以
#python manage.py runfcgi method=prefork host=127.0.0.1 port=9001
配置nginx.conf
server {
        listen       80;
        server_name  p.wraith.com;
        root /data0/htdocs/python;
        access_log  /data1/logs/python.access.log;
        error_log  /data1/logs/python.error.log;
 
        #配置django admin需要的文件
        location ~* ^/media/(css|img|js)/.*$ {
               root /usr/local/lib/python2.6/site-packages/django/contrib/admin;
               expires 30d;
               break;
       }
 
        location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
               access_log off;
               break;
       }
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|bmp|js)$ {
               expires 30d;
               break;
       }
        location / {
               fastcgi_pass unix:/tmp/python/python.sock;
                #如果上面是采用TCP的形式则
                #fastcgi_pass 127.0.0.1:9001;
                fastcgi_pass_header Authorization;
               fastcgi_intercept_errors off;
                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_param SERVER_PORT       $server_port;
               fastcgi_param SERVER_PROTOCOL   $server_protocol;
               fastcgi_param SERVER_NAME       $server_name;
                fastcgi_param REQUEST_URI       $request_uri;
               fastcgi_param DOCUMENT_URI      $document_uri;
               fastcgi_param DOCUMENT_ROOT     $document_root;
               fastcgi_param SERVER_ADDR       $server_addr;
               fastcgi_param REMOTE_USER       $remote_user;
               fastcgi_param REMOTE_ADDR       $remote_addr;
               fastcgi_param REMOTE_PORT       $remote_port;
               fastcgi_param SERVER_SOFTWARE   “nginx”;
               fastcgi_param GATEWAY_INTERFACE “CGI/1.1″;
        }
}
如果出现502错误的话,看一下python.sock的权限
如果不喜欢用Django也可以看看这里 http://timyang.net/tag/flup/

搭建nginx + python + django +memcached+ mysql +fastcgi 环境

3AUG 2009
作者:Mike.Xu 发表于: August 3, 2009 5:00 PM
转载时请务必以超链接形式标明文章 原始出处和作者信息及本版权声明
链接:http://www.dbasky.net/archives/2009/08/nginx-python-django-memcached-mysql-fastcgi.html
 Django是一个开放源代码的Web应用框架,由Python写成,它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的。python+django也是web开发者最受欢迎的框架.今天记录下整个搭建开发环境的过程.(说明下环境的系统为 centos 5.2)
一:更新yum仓库(目前这个yum源是最快的)

[root@filerserver python]#cd /etc/yum.repos.d
[root@filerserver python]#mv CentOS-Base.repo CentOS-Base.repo.save
[root@filerserver python]#wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
[root@filerserver python]#mv CentOS-Base.repo.5 CentOS-Base.repo

二:安装部分的开发包和更新

[root@filerserver python]#yum check-update
[root@filerserver python]#yum update
[root@filerserver python]#yum install ntp iptraf sysstat screen subversion wget bzip2 nfs-utils vim-common
[root@filerserver python]#yum install make gcc gcc-c++ libjpeg-devel libpng-devel zlib-devel tcl-devel freetype-devel libevent-devel openssl-devel db4-devel curl-devel pcre-devel ncurses-devel readline-devel sqlite-devel

三:安装Python

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/Python-2.5.4.tar.bz2
[root@filerserver python]#tar xjvf Python-2.5.4.tar.bz2
[root@filerserver python]#cd Python-2.5.4/
[root@filerserver python]#./configure –enable-unicode=ucs4
[root@filerserver python]#make
[root@filerserver python]#make install

四:安装MySQL客户端

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/mysql-5.0.45.tar.gz
[root@filerserver python]#tar zxvf mysql-5.0.45.tar.gz
[root@filerserver python]#cd mysql-5.0.45
[root@filerserver python]#CFLAGS=”-O3″ CXX=gcc CXXFLAGS=”-O3 -felide-constructors \
-fno-exceptions -fno-rtti” ./configure \
–prefix=/usr/local/mysql –enable-assembler \
–with-charset=utf8 \
–with-extra-charsets=gbk,gb2312,latin1 \
–without-debug \
–with-client-ldflags=-all-static \
–enable-thread-safe-client \
–without-server
[root@filerserver python]#make
[root@filerserver python]#make install
[root@filerserver python]#echo “PATH=/usr/local/mysql/bin:\$PATH” >> /etc/profile
[root@filerserver python]#echo “export PATH” >> /etc/profile
[root@filerserver python]#echo “/usr/local/mysql/lib/mysql” > /etc/ld.so.conf.d/mysql.conf
[root@filerserver python]#ldconfig

五:安装memcached

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/memcached-1.2.6.tar.gz
[root@filerserver python]#tar xzvf memcached-1.2.6.tar.gz
[root@filerserver python]#cd memcached-1.2.6/
[root@filerserver python]#./configure –prefix=/usr/local/memcached –enable-threads
[root@filerserver python]#make
[root@filerserver python]#make install

六:安装python setuptools

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/setuptools-0.6c9.tar.gz
[root@filerserver python]#tar xzvf setuptools-0.6c9.tar.gz
[root@filerserver python]#cd setuptools-0.6c9
[root@filerserver python]#python setup.py install

七:安装django

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#svn co http://code.djangoproject.com/svn/django/trunk django-trunk #直接重django的SVN拿最新稳定安装包
[root@filerserver python]#cd django-trunk
[root@filerserver python]#python setup.py install

八:安装sqlalchemy

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#svn co http://svn.sqlalchemy.org/sqlalchemy/branches/rel_0_4
[root@filerserver python]#cd sqlalchemy-0.4
[root@filerserver python]#python setup.py install

九:安装MySQLdb

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/MySQL-python-1.2.2.tar.gz
[root@filerserver python]#tar xzvf MySQL-python-1.2.2.tar.gz
[root@filerserver python]#cd MySQL-python-1.2.2
[root@filerserver python]#python setup.py install

十:安装Twisted

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/Twisted-8.2.0.tar.bz2
[root@filerserver python]#tar xjvf Twisted-8.2.0.tar.bz2
[root@filerserver python]#cd Twisted-8.2.0/
[root@filerserver python]#python setup.py install

十一:安装python-memcached

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/python-memcached-1.44.tar.gz
[root@filerserver python]#tar xzvf python-memcached-1.44.tar.gz
[root@filerserver python]#cd python-memcached-1.44
[root@filerserver python]#python setup.py install

十二:安装PIL

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/Imaging-1.1.6.tar.gz
[root@filerserver python]#tar xzvf Imaging-1.1.6.tar.gz
[root@filerserver python]#cd Imaging-1.1.6
[root@filerserver python]#python setup.py install

十三:安装flup

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/flup-1.0.1.tar.gz
[root@filerserver python]#tar xzvf flup-1.0.1.tar.gz
[root@filerserver python]#cd flup-1.0.1
[root@filerserver python]#python setup.py install

十四:安装simplejson

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/simplejson-2.0.9.tar.gz
[root@filerserver python]#tar xzvf simplejson-2.0.9.tar.gz
[root@filerserver python]#cd simplejson-2.0.9
[root@filerserver python]#python setup.py install

十五:安装nginx

[root@filerserver python]#cd /usr/local/src
[root@filerserver python]#wget http://www.dbasky.net/tool/python/nginx-0.7.51.tar.gz
[root@filerserver python]#tar xzvf nginx-0.7.51.tar.gz
[root@filerserver python]#cd nginx-0.7.51
[root@filerserver python]#./configure –prefix=/usr/local/nginx \
–with-md5=/usr/lib \
–with-sha1=/usr/lib \
–with-http_ssl_module \
–with-http_stub_status_module \
–without-mail_pop3_module \
–without-mail_imap_module \
–without-mail_smtp_module \
–with-http_realip_module
[root@filerserver python]#make
[root@filerserver python]#make install

到此这个环境搭建完成,这边说明我们为了提高架构的稳定性,可以在中间层加入个缓存数据库–TTserver,TTserver的安装和配置过程可以参考上篇日志–“兼容Memcached分布式持久存储系统—Tokyo Cabinet 和 Tokyo Tyrant 安装,配置“,这边就不多说了.

安装nginx,flup,django的fastcgi模式

2010-06-24 17:52:33|  分类: Nginx|字号 订阅

下载安装

主站

http://nginx.org/

下载

http://nginx.org/en/download.html

下载稳定版

http://nginx.org/download/nginx-0.7.67.zip

http://nginx.org/en/docs/

中文wiki

http://wiki.nginx.org/NginxChs

解压,运行nginx.exe,查看 http://localhost/,没问题就出现:

 

Welcome to nginx!


中止nginx进程

手工,做个bat批处理,多复制几行,因为至少有2个nginx.exe在运行中,taskkill是Window自带的

X:\> taskkill /f /im nginx.exe


配置

配置文件在 conf/nginx.conf

假设项目在E:/project/python/mysite

对应配置文件的写法 /cygdrive/E/project/python/mysite

对应配置文件的写法(或者是这种) E:/project/python/mysite

假设Python安装在 F:/Python25/

对应配置文件的写法 /cygdrive/F/Python25/

对应配置文件的写法(或者是这种) F:/Python25/

两种写法都测试一下

先用这段替换conf/nginx.conf的内容,原文件作备份,好习惯

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
worker_connections  64;
}

http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  ‘$remote_addr – $remote_user [$time_local] $request ‘
#                  ‘”$status” $body_bytes_sent “$http_referer” ‘
#                  ‘”$http_user_agent” “$http_x_forwarded_for”‘;

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
listen       80;
server_name  localhost;

#root   /cygdrive/D/html;
root   /cygdrive/E/project/python/mysite;
# 使用哪行,调试一下
#root   E:/project/python/mysite;
index  index.html index.htm;

charset utf-8;

#access_log  logs/host.access.log  main;

location ^~ /media/ {
alias        F:/Python25/Lib/site-packages/django/contrib/admin/media/;
#  使用哪行,调试一下
#alias        /cygdrive/F/Python25/Lib/site-packages/django/contrib/admin/media/;
}
# 静态资源
location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
expires 30d;
break;
}

location / {
# 指定 fastcgi 的主机和端口
fastcgi_pass 127.0.0.1:8051;
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_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
#    deny  all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

# HTTPS server
#
#server {
#    listen       443;
#    server_name  localhost;

#    ssl                  on;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#    ssl_prefer_server_ciphers   on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}


安装flup

简介

flup是用python实现的WSGI(网页网关接口)

主站

http://www.saddi.com/software/flup/dist/

下载

http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

解压

D:\setup\python\flup-1.0.2\flup-1.0.2

安装

X:\解压目录>python setup.py install

成功提示

Installed f:\python25\lib\site-packages\flup-1.0.2-py2.5.egg

Processing dependencies for flup==1.0.2

Finished processing dependencies for flup==1.0.2

或者用这种方式,只要环境配置好了(点这里

X:\任意目录下>easy_install http://www.saddi.com/software/flup/dist/flup-1.0.2-py2.5.egg


django的fastcgi模式

在8051这个端口为nginx提供服务,对应nginx配置文件中写的。还是做成bat处理,可以做成服务形式

X:\项目>python manage.py runfcgi method=threaded host=127.0.0.1 port=8051

manage.py runfcgi里面有一堆参数,查看参数

X:\项目> manage.py help runfcgi


都配置好了查看

http://localhost/

ok


参考

在windows上装 nginx + fastcgi + flup +django 终于装好了

http://hi.baidu.com/sinomazing/blog/item/611b8516e701d912972b43c9.html

nginx详细配置说明

http://www.westphp.com/bbs/thread-62-1-1.html

建立打开终端的快捷键

建立打开终端的快捷键

一、设置快捷键
首选项---屏幕快捷键,然后添加一个命令,并添加一个你的快捷键,如果你用的是gnome桌面建议用
gnome-terminal
命令添加快捷键,也可以用xterm,还可以用shell脚本,比如我用的是调用下面我贴的一个脚本
命令(脚本见文代码):/home/zhangwei/.gnome2/nautilus-scripts/打开终端
二、设置右键快捷键(打开时为当前目录)
方法一:
执行命令:sudo apt-get install nautilus-open-terminal
此方法是安装一个小软件,但是我安装后和conky冲突了,所以没有用。
方法二:
用脚本,把下面的脚本保存成任意名(我的是:打开终端),然后放在主目录的.gnome2/nautilus-scripts目录下,当然你可以放一些其他常见的脚本,都可以在右键找到。比如发送到邮件/修改文件权限等等实用的功能。
脚本:
#!/bin/bash
#
# This script opens a gnome-terminal in the directory you select.
#
# Distributed under the terms of GNU GPL version 2 or later
#
# Install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts
# You need to be running Nautilus 1.0.3+ to use scripts.

# When a directory is selected, go there. Otherwise go to current
# directory. If more than one directory is selected, show error.
if [ -n “$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS” ]; then
set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
if [ $# -eq 1 ]; then
destination=”$1″
# Go to file’s directory if it’s a file
if [ ! -d “$destination” ]; then
destination=”`dirname “$destination”`”
fi
else
zenity –error –title=”Error – Open terminal here” \
–text=”You can only select one directory.”
exit 1
fi
else
destination=”`echo “$NAUTILUS_SCRIPT_CURRENT_URI” | sed ‘s/^file:\/\///’`”
fi

# It’s only possible to go to local directories
if [ -n “`echo “$destination” | grep ‘^[a-zA-Z0-9]\+:’`” ]; then
zenity –error –title=”Error – Open terminal here” \
–text=”Only local directories can be used.”
exit 1
fi

cd “$destination”
exec x-terminal-emulator

Linux终端使用技巧
关键字: linux 终端
今天才发现Linux下的终端有这么多好用的快捷键。
Shift+Ctrl+T:新建标签页
Shift+Ctrl+W:关闭标签页
Ctrl+PageUp:前一标签页
Ctrl+PageDown:后一标签页
Shift+Ctrl+PageUp:标签页左移
Shift+Ctrl+PageDown:标签页右移
Alt+1:切换到标签页1
Alt+2:切换到标签页2
Alt+3:切换到标签页3
Shift+Ctrl+N:新建窗口
Shift+Ctrl+Q:关闭终端
终端中的复制/粘贴:
Shift+Ctrl+C:复制
Shift+Ctrl+V:粘贴
终端改变大小:
F11:全屏
Ctrl+plus:放大
Ctrl+minus:减小
Ctrl+0:原始大小