2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
7 # <jesse@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
52 fastcgi_server - external FastCGI server for RT
59 # start a server using defaults
62 # start server with custom option
63 fastcgi_server --socket /path/to/socket -n 5
64 fastcgi_server --port 12345 -n 5
68 This is a forking external FastCGI server for RT, it can be used
69 with apache and other servers supporting FastCGI technology.
71 An advantage is lower memory usage because of sharing memory
72 between process. It's easier to setup this with nginx and other
73 servers that can not maintain pool of fastcgi servers, apache
76 Disadvantage is that you have to start this server yourself and
77 monitor it, web servers wouldn't be able to restart it on crash.
83 =item -h, --help - get help
85 =item -n, --nprocesses - number of processes to start, by default 10
87 =item -s, --socket - socket path, by default F<RT/var/path/fastcgi.sock>
88 usually F</opt/rt3/var/fastcgi.sock>.
90 =item -p, --port - port to use instead of socket, by default socket is
93 =item --pidfile - pid file path, by default F<RT/var/path/fastcgi.pid>.
97 =head1 SERVER CONFIGURATION
101 Below you can find example of minimal config for nginx to run RT
102 with this FastCGI server. It's not ideal, but a good enough start.
105 events { worker_connections 1024; }
107 pid /opt/rt3/var/nginx/server.pid;
108 error_log /opt/rt3/var/nginx/error.log debug;
111 access_log /opt/rt3/var/nginx/access.log;
115 server_name localhost;
118 root /opt/rt3/share/html;
119 fastcgi_pass unix:/opt/rt3/var/fastcgi.sock;
121 fastcgi_param QUERY_STRING $query_string;
122 fastcgi_param REQUEST_METHOD $request_method;
123 fastcgi_param CONTENT_TYPE $content_type;
124 fastcgi_param CONTENT_LENGTH $content_length;
125 fastcgi_param PATH_INFO $fastcgi_script_name;
128 location /NoAuth/images/ {
129 alias /opt/rt3/share/html/NoAuth/images/;
138 server.name = "localhost"
141 server.username = "rt_web_user"
142 server.groupname = "rt_web_group"
144 server.pid-file = "/opt/rt3/var/lighthttpd/server.pid"
145 server.errorlog = "/opt/rt3/var/lighthttpd/error.log"
147 server.document-root = "/opt/rt3/share/html"
149 server.modules = ( "mod_fastcgi" )
152 "socket" => "/opt/rt3/var/fastcgi.sock",
153 "check-local" => "disable",
154 "fix-root-scriptname" => "enable",
163 no warnings qw(once);
165 package RT::Interface::Web::FCGI::Server;
166 use base qw(FCGI::ProcManager);
181 'h|help!' => \$opt{'help'},
182 's|socket=s' => \$opt{'socket'},
183 'p|port=s' => \$opt{'port'},
184 'n|nprocesses=s' => \$opt{'nprocesses'},
185 'pidfile=s' => \$opt{'pidfile'},
188 if ( $opt{'help'} ) {
190 Pod::Usage::pod2usage(
192 -exitval => $opt{'help'}? 0 : 1,
194 -sections => $opt{'help'}? 'NAME|USAGE|DESCRIPTION|OPTIONS' : 'NAME|USAGE',
198 $ENV{'RT_WEBMUX_HEAVY_LOAD'} = 1;
200 require (dirname(__FILE__) .'/webmux.pl');
202 unless ( $opt{'socket'} && $opt{'port'} ) {
204 $opt{'socket'} = File::Spec->catfile($RT::VarPath, 'fastcgi.sock');
206 elsif ( $opt{'port'} ) {
207 $opt{'socket'} = ':'. $opt{'port'};
209 $ENV{'FCGI_SOCKET_PATH'} = $opt{'socket'};
211 $opt{'pidfile'} ||= File::Spec->catfile($RT::VarPath, 'fastcgi.pid');
215 my $proc_manager = RT::Interface::Web::FCGI::Server->new({
216 n_processes => $opt{'nprocesses'} || 10,
217 pid_fname => $opt{'pidfile'},
220 $proc_manager->pm_manage();
222 while ( my $cgi = CGI::Fast->new ) {
223 $proc_manager->pm_pre_dispatch;
225 $ENV{'PATH'} = '/bin:/usr/bin';
226 $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'};
227 $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'};
228 $ENV{'ENV'} = '' if defined $ENV{'ENV'};
229 $ENV{'IFS'} = '' if defined $ENV{'IFS'};
231 Module::Refresh->refresh if RT->Config->Get('DevelMode');
232 RT::ConnectToDatabase();
234 # Each environment has its own way of handling .. and so on in paths,
235 # so RT consistently forbids such paths.
236 if ( $cgi->path_info =~ m{/\.} ) {
237 $RT::Logger->crit("Invalid request for ".$cgi->path_info." aborting");
238 print STDOUT "HTTP/1.0 400\r\n\r\n";
240 RT::Interface::Web::Handler->CleanupRequest();
241 $proc_manager->pm_post_dispatch;
246 my $interp = $RT::Mason::Handler->interp;
248 !$interp->comp_exists( $cgi->path_info )
249 && $interp->comp_exists( $cgi->path_info . "/index.html" )
251 $cgi->path_info( $cgi->path_info . "/index.html" );
255 eval { $RT::Mason::Handler->handle_cgi_object($cgi); };
257 $RT::Logger->crit($@);
259 RT::Interface::Web::Handler->CleanupRequest;
261 $proc_manager->pm_post_dispatch;