= Trac与FastCGI = 自0.9版本后, Trac支持通过[http://www.fastcgi.com/ FastCGI]接口运行. 像[wiki:ZhTracModPython mod_python], 它允许Trac保留在原处, 并且比外部的CGI接口(此接口必须为每个请求开始一个新进程)要快. 然而, 不像mod_python, 它能支持[http://httpd.apache.org/docs/suexec.html SuEXEC]. 另外, FastCGI也被更广范围的Web服务器支持. {{{ #!html
Windows用户注意: Trac的FCGI不能在Windows运行, 因为Windows没有实现_fcgi.py需要的Socket.fromfd
}}} == 简单的Apache配置 == 有两种FastCGI模式适用于Apache, `mod_fastcgi`和 `mod_fcgid`. 下面讨论的`FastCgiIpcDir` 和`FastCgiConfig`是`mod_fastcgi`指令, `DefaultInitEnv`是`mod_fgcid`指令. 对`mod_fastcgi`, 添加下面内容到相应的Apache配置文件中: {{{ # Enable fastcgi for .fcgi files # (If you're using a distro package for mod_fcgi, something like # this is probably already present)来自c00i90wn的注释: server.modules载入的顺序非常重要, 如果mod_auth在mod_fastcgi之前载入 , 服务器将无法验证用户.
}}} 为了验证, 你应启用lingttpd.conf'server.modules'中的mod_auth, 选择auth.backend和验证规则: {{{ server.modules = ( ... "mod_auth", ... ) auth.backend = "htpasswd" # 每个项目的独立的口令文件 # 请见 "Conditional Configuration" # http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/configuration.txt $HTTP["url"] =~ "^/first/" { auth.backend.htpasswd.userfile = "/path/to/projenv-first/htpasswd.htaccess" } $HTTP["url"] =~ "^/second/" { auth.backend.htpasswd.userfile = "/path/to/projenv-second/htpasswd.htaccess" } # 启用trac URL上的验证, 请见 # http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/authentication.txt auth.require = ("/first/login" => ("method" => "basic", "realm" => "First project", "require" => "valid-user" ), "/second/login" => ("method" => "basic", "realm" => "Second project", "require" => "valid-user" ) ) }}} 注意:如果口令文件不存在的话, ligttpd会停止运行(我用的是1.4.3版本). 注意:1.3.16之前的版本中, lighttpd不支持''有效的用户''('valid-user'). 条件配置对于映射静态资源也是有用的, 即, 直接将图片和CSS分发出去而不是通过FastCGI: {{{ # Aliasing functionality is needed server.modules += ("mod_alias") # 为静态资源设置一个别名 alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs") # 使用nagative lookahead来匹配trac下的任意资源的请求, 除非在/trac/chrome/common中 # 并对它们使用FastCGI $HTTP["url"] =~ "^/trac(?!/chrome/common)" { # 即使你有应用程序而不是Trac的其他的fastcgi.server声明, 不要使用下面设置 fastcgi.server = ("/trac" => ("trac" => ("socket" => "/tmp/trac-fastcgi.sock", "bin-path" => "/path/to/cgi-bin/trac.fcgi", "check-local" => "disable", "bin-environment" => ("TRAC_ENV" => "/path/to/projenv") ) ) ) } }}} 通过为每个项目创建一个别名, 并把对fastcgi.server的声明封装在条件配置块中的方法, 可以轻松地应用于多个项目. 还有一个方法来处理多项目, 它是使用TRAC_ENV_PARENT_DIR和全局验证而不是TRAC_ENV, 请看下面的一个例子: {{{ # 用于处理多个项目 alias.url = ( "/trac/" => "/path/to/trac/htdocs/" ) fastcgi.server += ("/projects" => ("trac" => ( "socket" => "/tmp/trac.sock", "bin-path" => "/path/to/cgi-bin/trac.fcgi", "check-local" => "disable", "bin-environment" => ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" ) ) ) ) #此处开启了全局验证配置 auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd" $HTTP["url"] =~ "^/projects/.*/login$" { auth.require = ("/" => ( "method" => "basic", "realm" => "trac", "require" => "valid-user" ) ) } }}} 通过环境变量LC_TIME, lighttpd也支持更改日期或时间格式. {{{ fastcgi.server = ("/trac" => ("trac" => ("socket" => "/tmp/trac-fastcgi.sock", "bin-path" => "/path/to/cgi-bin/trac.fcgi", "check-local" => "disable", "bin-environment" => ("TRAC_ENV" => "/path/to/projenv", "LC_TIME" => "ru_RU") ) ) ) }}} 关于语言规格的细节, 请参见`TracFaq question 2.13`. 像[http://trac.lighttpd.net/trac/wiki/TracInstall 升级后的安装说明]的重要信息, [wiki:TracCgi#MappingStaticResources 还有这里]对于非fastcgi安装方面是有帮助的. 如果你使用trac-0.9, 阅读[http://lists.edgewall.com/archive/trac/2005-November/005311.html 关于一些bug] 重新启动lighttpd并浏览`http://yourhost.example.org/trac`来访问Trac. 注意关于运行lighttpd的几点: 如果没有别的办法, 并且trac.fcgi没有跟lighttpd设置(server.username = "www-data", server.groupname = "www-data")启动, 那么, 在bin-environment 段中设置PYTHON_EGG_CACHE为www-data的主目录, 或者该帐户有写权限的其他目录. == 简单的LiteSpeed配置 == FastCGI前端主要是为了与另外的Web服务器一起使用而开发的, 例如[http://www.litespeedtech.com/ LiteSpeed]. LiteSpeedWeb服务器是一个事件驱动的异步Apache的替代物, 从其最开始起, 就是以安全的, 扩展性和最低资源消耗为设计目标. LiteSpeed可以直接从一个Apache配置文件进行操作, 并且目标定位于重要的商业环境. 安装: 1) 请确保你首先有安装一个Trac项目. 首先用"tracd"测试其安装. 2) 为该安装创建一个虚拟机. 从现在开始, 我们会将这个虚拟机叫做TracVhost. 对于该指南, 我们会假设, 你的trac项目会通过下列实现: {{{ http://yourdomain.com/trac/ }}} 3) 到''TracVhost → External Apps''选项卡, 并创建一个新的''外部程序''. {{{ Name: MyTracFCGI Address: uds://tmp/lshttpd/mytracfcgi.sock Max Connections: 10 Environment: TRAC_ENV=/fullpathto/mytracproject/ <--- path to root folder of trac project Initial Request Timeout (secs): 30 Retry Timeout (secs): 0 Persistent Connection Yes Connection Keepalive Timeout: 30 Response Bufferring: No Auto Start: Yes Command: /usr/share/trac/cgi-bin/trac.fcgi <--- path to trac.fcgi Back Log: 50 Instances: 10 }}} 4) 可选的. 如果你需要使用基于htpasswd的验证. 选择''TracVhost → Security(安全)''选项卡并创建一个新的安全''域''. {{{ DB Type: Password File Realm Name: MyTracUserDB <--- any name you wish and referenced later User DB Location: /fullpathto/htpasswd <--- path to your htpasswd file }}} 如果你没有htpasswd文件或者不知道如何在其中创建选项, 访问http://sherylcanter.com/encrypt.php去创建''用户:密码''. 5) 选择''PythonVhost → Contexts''并创建一个新的"FCGI Context". {{{ URI: /trac/ <--- URI path to bind to python fcgi app we created Fast CGI App: [VHost Level] MyTractFCGI <--- select the trac fcgi extapp we just created Realm: TracUserDB <--- only if (4) is set. select realm created in (4) }}} 6) 更改/fullpathto/mytracproject/conf/trac.ini. {{{ #find/set base_rul, url, and link variables base_url = http://yourdomain.com/trac/ <--- base url to generate correct links to url = http://yourdomain.com/trac/ <--- link of project link = http://yourdomain.com/trac/ <--- link of graphic logo }}} 7) 重新启动LiteSpeed, ''lswsctrl restart'', 并在以下地址访问你的新Trac项目: {{{ http://yourdomain.com/trac/ }}} ---- 原文版本: TracFastCgi[[BR]] 相关信息: [ZhTracCgi TracCgi], [ZhTracModPython ModPython], [ZhTracInstall Trac安装], [ZhTracGuide Trac导览][[BR]] See also: TracCgi, TracModPython, TracInstall, TracGuide