用 FastCGI 连接 Nginx 和 Zope

跟用 Apache 相比小有一点麻烦,需要配置一下。

location ~ /zope(/|$) {
    fastcgi_pass unix:/var/run/plone-site.sock;
    include /etc/nginx/fastcgi_params;

    set $fixed_content_length $content_length;
    if ( $fixed_content_length = "" ) {
        set $fixed_content_length "0";
    }

    set $path_info "/";
    if ( $document_uri ~ "^/zope(/.*)$" ) {
        set $path_info $1;
    }

    fastcgi_param CONTENT_LENGTH $fixed_content_length;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param SCRIPT_NAME /zope;
}

主要原因是, Zope 对 SCRIPT_NAMEPATH_INFO 两个参数的要求是以 Apache 方式为基准的, Nginx 的方式无法分辨出访问的对象标识。看了一下 CGI 标准,应该是 Nginx 的做法站不住脚,但好在可以通过配置来解决。另外, Zope 直接把 CONTENT_LENGTH 的值(字符串)丢给 aoti 而这个函数在字符串为空时会抛出异常, Zope 没考虑到这一点,所以也要修正一下。

顺便感慨,把这条技巧加到 Nginx Wiki 里的时候,看了一下历史变动,里面有相当多的中文 spam 广告被管理员删掉的记录,汗啊。

评论

最近研究了在nginx下部署pylons应用,和你这个有相

最近研究了在nginx下部署pylons应用,和你这个有相似的地方(才看到你的),分享下: http://www.garyshi.net/2011/01/deploy-pylons-applications-for-nginx-with-fastcgi/

发表新评论

此内容将保密,不会被其他人看见。
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.