Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1105983
  • 博文数量: 276
  • 博客积分: 8317
  • 博客等级: 少将
  • 技术积分: 2329
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-12 08:17
个人简介

http://ads.buzzcity.net/adpage.php?partnerid=40096

文章分类

全部博文(276)

文章存档

2013年(1)

2012年(38)

2011年(102)

2010年(85)

2009年(45)

2008年(5)

分类: 系统运维

2012-08-06 15:01:49

大家都知道,Nginx上跑django是用fastcgi模式,因此先安装flup:
$ emerge flup
然后安装Nginx,这一点要注意,需要添加fastcgi支持,否则启动时会报错:unknown directive "fastcgi_pass",命令如下:
$ USE=fastcgi emerge nginx
之后就是配置nginx了,不废话,配置文件如下(/etc/nginx/nginx.conf):
user nginx nginx;
worker_processes 1;
error_log /var/log/nginx/error_log info;
events {
    worker_connections  8192;
    use epoll;
}
http {
    include        /etc/nginx/mime.types;
    default_type    application/octet-stream;
    log_format main
        '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$gzip_ratio"';
    client_header_timeout    10m;
    client_body_timeout    10m;
    send_timeout        10m;
    connection_pool_size        256;
    client_header_buffer_size    1k;
    large_client_header_buffers    4 2k;
    request_pool_size        4k;
    gzip on;
    gzip_min_length    1100;
    gzip_buffers    4 8k;
    gzip_types    text/plain;
    output_buffers    1 32k;
    postpone_output    1460;
    sendfile    on;
    tcp_nopush    on;
    tcp_nodelay    on;
    keepalive_timeout    75 20;
    ignore_invalid_headers    on;
    index index.html;
        server {
                listen 80;
                server_name localhost;
                # site_media - folder in uri for static files
                location ^~/site_media {
                        alias /var/www/meiweier/site_media/;
        }
                location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
                      access_log   off; # po co mi logi obrazków :)
                      expires      30d;
                }
                location / {
                        # host and port to fastcgi server
                        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_intercept_errors off;
                }
                access_log       /var/log/nginx/localhost.access_log main;
                error_log        /var/log/nginx/localhost.error_log;
        } 
}
启动网站fastcgi的脚本:
#!/bin/bash
# Replace these three settings.
PROJDIR="/var/www/meiweier"
PIDFILE="$PROJDIR/meiweier.pid"
SOCKET="$PROJDIR/meiweier.sock"
cd $PROJDIR
if [ -f $PIDFILE ]; then
    kill `cat -- $PIDFILE`
        rm -f -- $PIDFILE
        fi
        exec /usr/bin/env - \
          PYTHONPATH="../python:.." \
            python $PROJDIR/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=$PIDFILE
添加执行权限:
$ chmod +x meiweier.sh
添加到启动,这样系统启动时自动启动nginx和网站的fastcgi进程:
$ rc-update –add nginx default
$ rc-update –add meiweier.sh default
注意,要先将meiweier.sh拷贝到/etc/init.d目录下。

本文出自 “江湖” 博客,请务必保留此出处http://firefish.blog.51cto.com/298258/251844

阅读(805) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~