将 Request Tracker 与 Lighttpd 结合使用(通过 FastCGI,使用 Mason)¶
Best Practical Solutions 的 Request Tracker (RT) 是一款企业级票务系统,它能让一群人智能高效地管理用户社区提交的任务、问题和请求,该系统可与 Lighttpd 结合使用。
设置 RT3 与 将 Mason 与 Lighttpd 和 FastCGI 结合使用 有些类似,除了一些细微的配置差异。
在 Lighttpd 上设置 RT 需要以下条件:- 满足 RT 的所有 Perl 依赖项
- Mason 处理以 '/' 或 '.html' 或 '.css' 或 '.js' 结尾的文件。
- Mason 处理“mail-gateway”,RT 邮件网关需要此功能。
- Mason 处理“Search/Chart”,图表化搜索结果需要此功能。
- Mason 处理“Search/Results.rdf”,RSS 搜索结果订阅需要此功能。
- Mason 处理“Search/Results.tsv”,用于下载搜索结果为电子表格。
- 其他由 Lighttpd 静态提供服务的文件
- FastCGI 进程启动时加载所需的 Perl 模块。
- 禁止访问 .mhtml 文件。
本文档假定您将 Request Tracker 安装在 /opt/rt3/。
首先我们需要一个 Mason 处理器,它是 RT 安装中自带处理器的修补版本。Lighttpd 将通过 FastCGI 使用此处理器。在我的设置中,该处理器名为 mason_lighttpd_handler.fcgi,它不需要位于任何特定位置。
#!perl #!/usr/bin/perl # BEGIN BPS TAGGED BLOCK {{{ # # COPYRIGHT: # # This software is Copyright (c) 1996-2006 Best Practical Solutions, LLC # <jesse@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) # # # LICENSE: # # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have # been provided with this software, but in any event can be snarfed # from www.gnu.org. # # This work is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # CONTRIBUTION SUBMISSION POLICY: # # (The following paragraph is not intended to limit the rights granted # to you to modify and distribute this software under the terms of # the GNU General Public License and is only of importance to you if # you choose to contribute your changes and enhancements to the # community by submitting them to Best Practical Solutions, LLC.) # # By intentionally submitting any modifications, corrections or # derivatives to this work, or any other work intended for use with # Request Tracker, to Best Practical Solutions, LLC, you confirm that # you are the copyright holder for those contributions and you grant # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, # royalty-free, perpetual, license to use, copy, create derivative # works based on those contributions, and sublicense and distribute # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} package RT::Mason; use strict; use vars '$Handler'; use File::Basename; require ('/opt/rt3/bin/webmux.pl'); # Enter CGI::Fast mode, which should also work as a vanilla CGI script. require CGI::Fast; my $h; RT::Init(); while ( my $cgi = CGI::Fast->new ) { # the whole point of fastcgi requires the env to get reset here.. # So we must squash it again $ENV{'PATH'} = '/bin:/usr/bin'; $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'}; $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'}; $ENV{'ENV'} = '' if defined $ENV{'ENV'}; $ENV{'IFS'} = '' if defined $ENV{'IFS'}; my $uri = $ENV{REQUEST_URI}; if ($uri =~ /\?/) { $uri =~ /^(.*?)\?(.*)/; $ENV{PATH_INFO} = $1; $ENV{QUERY_STRING} = $2; } else { $ENV{PATH_INFO} = $uri; $ENV{QUERY_STRING} = ""; } Module::Refresh->refresh if $RT::DevelMode; RT::ConnectToDatabase(); if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) ) && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) { $cgi->path_info( $cgi->path_info . "/index.html" ); } eval { $Handler->handle_cgi_object($cgi); }; if ($@) { $RT::Logger->crit($@); } RT::Interface::Web::Handler->CleanupRequest(); } 1;
现在我们设置用于 RT 安装的主机,告诉 Lighttpd 通过 FastCGI 将所有必要的请求传递给该站点。
#!python $HTTP["host"] =~ "site1\.example\.com" { # Specify the documentroot server.document-root = "/opt/rt3/share/html" # Map appropriate files and extensions fastcgi.map-extensions = ( ".css" => ".html", ".js" => ".html", "/" => ".html", "mail-gateway" => ".html", "Search/Chart" => ".html", "Search/Results.rdf" => ".html", "Search/Results.tsv" => ".html" ) # Set Lighttpd to check for an index.html file for each directory index-file.names = ( "index.html" ) # Disallow access to .mhtml files url.access-deny = ( ".mhtml" ) setenv.add-environment = ( "SCRIPT_NAME" => "/", ) # Set up an alias for the /NoAuth/images location url.rewrite-once = ( "^/(?!NoAuth/images/)(.*)" => "/$1", ) # Add trailing slash so attachment downloads work url.rewrite-once = ( "^(.*)/Ticket/Attachment/(.*)" => "/$1/Ticket/Attachment/$2/" ) # Set up FastCGI handler fastcgi.server = ( ".html" => (( "socket" => "/tmp/rt-fcgi.socket", "bin-path" => "/opt/rt3/bin/mason_lighttpd_handler.fcgi", "check-local" => "disable", "min-procs" => 2, "max-procs" => 2 )) ) }
就这样!
上述 Lighttpd 配置将启动两个 Mason 处理器脚本实例,并根据需要将请求传递给它们。
鸣谢¶
感谢 Justin Hawkins <justin@hawkins.id.au> 撰写了最初的 将 Mason 与 Lighttpd 结合使用(通过 FastCGI) 一文。
替代版本¶
上述 Lighttpd 配置会破坏所有依赖于 Mason 默认处理器(dhandler)的 RT 功能,例如工单依赖图和富文本编辑。基本上,本应通过 FastCGI 处理的请求却没有被处理,因为查询没有以“.html”结尾。在某些情况下,可以通过使用 map-extensions 和/或 URL 重写(例如附件)来解决这个问题,而在其他情况下则不可能。
真正的解决方案是创建一个类似 map-extensions 的机制,可以匹配查询字符串的开头(或者更好,匹配正则表达式)。与此同时,可以通过 fastcgi.server 的多个实例来实现类似的结果,这些实例引用一个并提供它们自己的前缀,但这样就会出现哪个实例应该启动 FastCGI 后端的冲突。
相反,我修改了 Apache 配置,使其变得更简单,所有请求都通过 Mason 处理。这当然会慢一点,但这些静态内容无论如何都会在客户端缓存。
# server.{modules, port, pid-file} statements skipped var.root = "/somewhere" # Adjust according to your installation path server.document-root = root + "/rt/share/html" # Set Lighttpd to check for an index.html file for each directory index-file.names = ( "index.html" ) # Handle ALL requests through Mason fastcgi.server = ( "/" => (( "socket" => root + "/rt-fcgi.socket", "bin-path" => root + "/rt_mason_handler.fcgi", "check-local" => "disable", "min-procs" => 4, "max-procs" => 8 )), )
- Thomas Equeter