Differences between revisions 11 and 12
Revision 11 as of 2007-03-07 03:18:35
Size: 9332
Editor: ZoomQuiet
Comment:
Revision 12 as of 2007-03-07 03:34:55
Size: 10811
Editor: ZoomQuiet
Comment:
Deletions are marked like this. Additions are marked like this.
Line 255: Line 255:
== 稳定思绪 ==
 * 专注Lighttpd:
  1. 重新配置 `.fcgi` 使用 端口发布方式,比较容易在系统中观察到
  1. 重新配置`lighttpd.conf` 配合 `.fcgi`
 * 所以{{{
... obp.fcgi
#!/bin/sh
PROJDIR="/usr/local/www/data/obp/trunk/openbookplatform"
PIDFILE="$PROJDIR/obp.pid"
SOCKET="$PROJDIR/obp.sock"

cd $PROJDIR
if [ -f $PIDFILE ]; then
kill `cat -- $PIDFILE`
rm -f -- $PIDFILE
fi

/usr/local/bin/python \
./manage.py runfcgi \
method=threaded host=127.0.0.1 port=3033 pidfile=$PIDFILE

... lighttpd.conf
### zoomq::070306 for fascgi pub Django
$HTTP["host"] == "obp.zoomquiet.org" {
    server.document-root = "/usr/local/www/data/obp/trunk/openbookplatform"
    fastcgi.server = (
        "/obp.fcgi" => (
            "main" => (
                # Use host / port instead of socket for TCP fastcgi
                "host" => "127.0.0.1",
                "port" => 3033,
                #"socket" => "/usr/local/www/data/obp/trunk/openbookplatform/obp.sock",
                "check-local" => "disable",
            )
        ),
    )
    alias.url = (
        "/site_media/" => "/usr/local/www/data/obp/trunk/openbookplatform/media/",
    )
    url.rewrite-once = (
        "^(/site_media.*)$" => "$1",
        "^/favicon\.ico$" => "/site_media/favicon.ico",
        "^(/.*)$" => "/obp.fcgi$1",
    )
}
}}}
 * 运行!哈哈哈!看来有戏!终于可以看到Django 了!
attachment:snap_errorDB.png

继续研究尝试 ::-- ZoomQuiet [DateTime(2007-03-06T14:14:46Z)] TableOfContents

1. apache+fastcgi

1.1. 准备

  • 因为需要将 SVN 通过 HTTP 进行发布,所以 Lighttpd 无法进行转移到 apache22

{{{#确保以下模块安装成功 LoadModule dav_module libexec/apache22/mod_dav.so LoadModule dav_svn_module libexec/apache22/mod_dav_svn.so LoadModule authz_svn_module libexec/apache22/mod_authz_svn.so

LoadModule python_module libexec/apache22/mod_python.so LoadModule fastcgi_module libexec/apache22/mod_fastcgi.so }}}

  • 配置apache

    <VirtualHost *:80>
        ServerName obp.zoomquiet.org
        DocumentRoot /path/to/web/site/root/htdocs
        <Directory "/path/to/web/site/root/htdocs">
           Options Indexes FollowSymLinks
           AllowOverride None
           Order allow,deny
           Allow from all
        </Directory>   
    
        #Zoomq::070306 for SVN repos
        <Location /svn>  
            DAV svn
            SVNParentPath /usr/local/repos
            # our access control policy
            AuthzSVNAccessFile /usr/local/repos/matter/conf/authz.cfg
            # try anonymous access first, resort to real 
            # authentication if necessary.
            Satisfy Any
            Require valid-user
            # how to authenticate a user
            AuthType Basic
            AuthName "zoomquiet.org repository"
            AuthUserFile /usr/local/repos/svn.htpasswd
            SVNIndexXSLT "/svnindex.xsl"
        </Location>
    </VirtualHost>

1.2. 51boo方式

  • 参考 [:ObpLatform/2007-02-24:limodou的配置]
  • 完成 django.fsgi{{{#!/usr/local/bin/python

import sys, os sys.path = [,

  • '/usr/local/www/data/obp/trunk', '/usr/local/www/data/obp/trunk/openbookplatform'] + sys.path

# Set the DJANGO_SETTINGS_MODULE environment variable. os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.core.servers.fastcgi import runfastcgi runfastcgi(["method=threaded", "daemonize=false", "pidfile=pidfile"]) }}}

  • 配置apache

<VirtualHost *:80>
    ServerName obp.zoomquiet.org
...
    RewriteEngine On
    #RewriteBase /
    RewriteLogLevel 1
    RewriteLog "/var/log/httpd/rewrite.log"
    
    Alias /openbookplatform "/usr/local/www/data/obp/trunk/openbookplatform"
    <Directory "/usr/local/www/data/obp/trunk/openbookplatform">
        AddHandler fcgid-script .fcgi
        Options +FollowSymLinks +ExecCGI
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]
    </Directory>   

1.2.1. 结果

重启 apache 成功

Forbidden

You don't have permission to access /openbookplatform on this server.
  • 直接运行django.fcgi

     ./django.fcgi
    WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
    WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
    WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
    WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
    Traceback (most recent call last):
      File "/usr/local/lib/python2.4/site-packages/flup-0.5-py2.4.egg/flup/server/fcgi_base.py", line 558, in run
        protocolStatus, appStatus = self.server.handler(self)
      File "/usr/local/lib/python2.4/site-packages/flup-0.5-py2.4.egg/flup/server/fcgi_base.py", line 1112, in handler
        result = self.application(environ, start_response)
      File "/usr/local/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
        response = self.get_response(request)
      File "/usr/local/lib/python2.4/site-packages/django/core/handlers/base.py", line 59, in get_response
        response = middleware_method(request)
      File "/usr/local/lib/python2.4/site-packages/django/middleware/common.py", line 41, in process_request
        if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]):
    IndexError: string index out of range
    Content-Type: text/html
  • 怀疑是定制过 Djnago 的和 官方文档没有相类之处,先放下

1.3. Django 方式

{{{#!/bin/bash

# Replace these three settings. PROJDIR="/usr/local/www/data/obp/trunk/openbookplatform" PIDFILE="$PROJDIR/obp.pid" SOCKET="$PROJDIR/obp.sock"

cd $PROJDIR if [ -f $PIDFILE ]; then kill cat -- $PIDFILE rm -f -- $PIDFILE fi

exec /usr/bin/env - \ PYTHONPATH="../python:.." \ ./manage.py runfcgi socket=$SOCKET pidfile=$PIDFILE }}}

  • 配置apache

FastCGIExternalServer /usr/local/www/data/obp/trunk/openbookplatform/obp.fcgi -host 127.0.0.1:3033
<VirtualHost *:80>
    ServerName obp.zoomquiet.org
...
    RewriteEngine On
    #RewriteBase /
    RewriteLogLevel 1
    RewriteLog "/var/log/httpd/rewrite.log"
    RewriteRule ^/(media.*)$ /usr/local/www/data/obp/trunk/openbookplatform/media/$1 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ /obp.fcgi/$1 [QSA,L]
...

1.3.1. 结果

重启 apache 成功

Not Found

The requested URL / was not found on this server.

1.4. 继续试探

  • 尝试修订 obp.fcgi{{{#!/bin/sh

# Replace these three settings. PROJDIR="/usr/local/www/data/obp/trunk/openbookplatform" PIDFILE="$PROJDIR/obp.pid" SOCKET="$PROJDIR/obp.sock" if [ -f $PIDFILE ]; then kill cat -- $PIDFILE rm -f -- $PIDFILE fi /usr/local/bin/python \ ./manage.py runfcgi socket=$SOCKET pidfile=$PIDFILE }}}

  • 可以直接运行{{{$ sockstat

... zoomq python 51196 3 stream /usr/local/www/data/obp/trunk/openbookplatform/obp.sock zoomq python 51196 4 stream -> ?? zoomq python 51195 3 stream /usr/local/www/data/obp/trunk/openbookplatform/obp.sock zoomq python 51195 4 stream -> ?? zoomq python 51194 3 stream /usr/local/www/data/obp/trunk/openbookplatform/obp.sock zoomq python 51194 4 stream -> ?? zoomq python 51193 3 stream /usr/local/www/data/obp/trunk/openbookplatform/obp.sock zoomq python 51193 4 stream -> ?? zoomq python 51192 3 stream /usr/local/www/data/obp/trunk/openbookplatform/obp.sock zoomq python 51192 4 stream -> ?? zoomq python 51191 3 stream /usr/local/www/data/obp/trunk/openbookplatform/obp.sock }}}

  • 成功!可以观察到{{{#sockstat

USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS zoomq python 50875 3 stream /home/zoomq/obp.sock zoomq python 50875 4 stream -> ?? zoomq python 50874 3 stream /home/zoomq/obp.sock zoomq python 50874 4 stream -> ?? zoomq python 50873 3 stream /home/zoomq/obp.sock zoomq python 50873 4 stream -> ?? zoomq python 50872 3 stream /home/zoomq/obp.sock zoomq python 50872 4 stream -> ?? zoomq python 50871 3 stream /home/zoomq/obp.sock zoomq python 50871 4 stream -> ?? zoomq python 50870 3 stream /home/zoomq/obp.sock }}}

  • 修订apache

    FastCGIExternalServer /usr/local/www/data/obp/trunk/openbookplatform/obp.fcgi -socket /usr/local/www/data/obp/trunk/openbookplatform/obp.sock
    <VirtualHost 210.192.102.145:80>
        ServerName obp.zoomquiet.org
        DocumentRoot /usr/local/www/data/obp/trunk/openbookplatform
    ...
  • 结果重启成功,访问 http://obp.zoomquiet.org/

    Forbidden
    
    You don't have permission to access / on this server
  • 观察 rewrite.log

    61.135.152.194 - - [06/Mar/2007:22:47:18 +0800] [obp.zoomquiet.org/sid#8148ce8][rid#82e1050/initial] (1) go-ahead with /usr/local/www/data/obp/trunk/openbookplatform/obp.fcgi/ [OK]
    是成功的....

2. lighttpd+fastcgi

急了!!!

  • 设计使用 lighttpd 快速发布fastcgi 然后通过 apache 统一rewrite 发布好了
  • lighttpd.conf

### zoomq::070306 for fascgi pub Django
$HTTP["host"] == "obp.zoomquiet.org" {
    server.document-root = "/usr/local/www/data/obp/trunk/openbookplatform"
    fastcgi.server = (
        "/obp.fcgi" => (
            "main" => (
                # Use host / port instead of socket for TCP fastcgi
                # "host" => "127.0.0.1",
                # "port" => 3033,
                "socket" => "/usr/local/www/data/obp/trunk/openbookplatform/obp.sock",
                "check-local" => "disable",
            )
        ),
    )
    alias.url = (
        "/site_media/" => "/usr/local/www/data/obp/trunk/openbookplatform/media/",
    )
    url.rewrite-once = (
        "^(/site_media.*)$" => "$1",
        "^/favicon\.ico$" => "/site_media/favicon.ico",
        "^(/.*)$" => "/obp.fcgi$1",
    )
}
  • 结果 ....

    2007-03-07 11:05:33: (mod_fastcgi.c.1690) connect failed: Socket operation on non-socket 0 /usr/local/www/data/obp/trunk/openbookplatform/obp.sock
    2007-03-07 11:05:44: (mod_fastcgi.c.2682) fcgi-server re-enabled:  0 /usr/local/www/data/obp/trunk/openbookplatform/obp.sock

2.1. 稳定思绪

  • 专注Lighttpd:
    1. 重新配置 .fcgi 使用 端口发布方式,比较容易在系统中观察到

    2. 重新配置lighttpd.conf 配合 .fcgi

  • 所以

    ... obp.fcgi
    #!/bin/sh
    PROJDIR="/usr/local/www/data/obp/trunk/openbookplatform"
    PIDFILE="$PROJDIR/obp.pid"
    SOCKET="$PROJDIR/obp.sock"
    
    cd $PROJDIR
    if [ -f $PIDFILE ]; then
    kill `cat -- $PIDFILE`
    rm -f -- $PIDFILE
    fi
    
    /usr/local/bin/python \
    ./manage.py runfcgi \
    method=threaded host=127.0.0.1 port=3033  pidfile=$PIDFILE
    
    ... lighttpd.conf
    ### zoomq::070306 for fascgi pub Django
    $HTTP["host"] == "obp.zoomquiet.org" {
        server.document-root = "/usr/local/www/data/obp/trunk/openbookplatform"
        fastcgi.server = (
            "/obp.fcgi" => (
                "main" => (
                    # Use host / port instead of socket for TCP fastcgi
                    "host" => "127.0.0.1",
                    "port" => 3033,
                    #"socket" => "/usr/local/www/data/obp/trunk/openbookplatform/obp.sock",
                    "check-local" => "disable",
                )
            ),
        )
        alias.url = (
            "/site_media/" => "/usr/local/www/data/obp/trunk/openbookplatform/media/",
        )
        url.rewrite-once = (
            "^(/site_media.*)$" => "$1",
            "^/favicon\.ico$" => "/site_media/favicon.ico",
            "^(/.*)$" => "/obp.fcgi$1",
        )
    }
  • 运行!哈哈哈!看来有戏!终于可以看到Django 了!

attachment:snap_errorDB.png

3. 反馈

PageComment2

ObpLatform/2007-03-06 (last edited 2009-12-25 07:15:49 by localhost)