FastCGI and nginx support for gitweb
cover FastCGI and nginx support for gitweb
I was looking at nginx for another project and got sidetracked into writing instaweb support for it; so I ended up writing a simple FCGI wrapper for gitweb as well.
--- .gitignore | 1 + Makefile | 11 ++++++- git-instaweb.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++- gitweb/gitweb-fcgi.perl | 51 +++++++++++++++++++++++++++++++++ gitweb/gitweb.perl | 1 + 5 files changed, 134 insertions(+), 2 deletions(-)
Signature · 1 line
Eric Wong
PATCH 1/2 gitweb: add a simple wrapper for FCGI support
The FCGI wrapper is designed to be spawned from the command-line, and can be backgrounded there. No FCGI-specific spawners are necessary.
Since we re-eval gitweb.cgi on every request, I've quieted warnings for redefined functions.
--- .gitignore | 1 + Makefile | 6 +++++ gitweb/gitweb-fcgi.perl | 51 +++++++++++++++++++++++++++++++++++++++++++++++ gitweb/gitweb.perl | 1 + 4 files changed, 59 insertions(+), 0 deletions(-)
.gitignore +1 -0
@@ -137,6 +137,7 @@ git-whatchanged git-write-tree git-core-*/?* gitweb/gitweb.cgi +gitweb/gitweb.fcgi test-date test-delta test-dump-cache-tree
Makefile +6 -0
@@ -684,6 +684,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl chmod +x $@+ mv $@+ $@ +gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl + rm -f $@ $@+ + sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' $< >$@+ + chmod +x $@+ + mv $@+ $@ + git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css rm -f $@ $@+ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
gitweb/gitweb-fcgi.perl new file +51 -0
51 lines not on this page · raw message
gitweb/gitweb.perl +1 -0
@@ -9,6 +9,7 @@ use strict; use warnings; +no warnings qw(redefine); # for FCGI use CGI qw(:standard :escapeHTML -nosticky); use CGI::Util qw(unescape); use CGI::Carp qw(fatalsToBrowser);
Signature · 1 line
1.5.0.rc0.gcafca-dirty
PATCH 2/2 instaweb: add support for nginx + FastCGI
In reply to Eric Wongnginx does not support regular CGI
--- Makefile | 5 +++- git-instaweb.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-)
Makefile +4 -1
@@ -690,7 +690,8 @@ gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl chmod +x $@+ mv $@+ $@ -git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css +git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css \ + gitweb/gitweb.fcgi rm -f $@ $@+ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -699,6 +700,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css -e '/@@GITWEB_CGI@@/d' \ -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \ -e '/@@GITWEB_CSS@@/d' \ + -e '/@@GITWEB_FCGI@@/r gitweb/gitweb.fcgi' \ + -e '/@@GITWEB_FCGI@@/d' \ [email protected] > $@+ chmod +x $@+ mv $@+ $@
git-instaweb.sh +71 -1
112 lines not on this page · raw message
Signature · 1 line
1.5.0.rc0.gcafca-dirty
Quoted 3 lines · Eric Wong
I was looking at nginx for another project and got sidetracked into writing instaweb support for it; so I ended up writing a simple FCGI wrapper for gitweb as well.
FCGI, not CGI::Fast?
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Quoted 7 lines · Jakub Narebski
Quoted 3 lines · Eric Wong
I was looking at nginx for another project and got sidetracked into writing instaweb support for it; so I ended up writing a simple FCGI wrapper for gitweb as well.
FCGI, not
CGI::Fast?
CGI::Fast is just a wrapper on top of FCGI but gives access to functions in the CGI module. We already use the CGI module explicitly in gitweb; and I didn't want to make deeper changes in gitweb nor introduce extra dependencies.
Signature · 1 line
Eric Wong
Re: [PATCH 1/2] gitweb: add a simple wrapper for FCGI support
In reply to Eric WongQuoted 7 lines · Eric Wong
The FCGI wrapper is designed to be spawned from the command-line, and can be backgrounded there. No FCGI-specific spawners are necessary.
Since we re-eval gitweb.cgi on every request, I've quieted warnings for redefined functions.
I never did submit this; perhaps I should've...
http://utsl.gen.nz/gitweb/?p=gitweb;a=commitdiff;h=56d7d436;hp=2326acfa
Sam.
Quoted 106 lines
Signed-off-by Eric Wong <[email protected]>--- .gitignore | 1 + Makefile | 6 +++++ gitweb/gitweb-fcgi.perl | 51 +++++++++++++++++++++++++++++++++++++++++++++++ gitweb/gitweb.perl | 1 + 4 files changed, 59 insertions(+), 0 deletions(-).gitignore +1
-0@@ -137,6 +137,7 @@ git-whatchanged git-write-tree git-core-*/?* gitweb/gitweb.cgi +gitweb/gitweb.fcgi test-date test-delta test-dump-cache-treeMakefile +6
-0@@ -684,6 +684,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl chmod +x $@+ mv $@+ $@ +gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl + rm -f $@ $@+ + sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' $< >$@+ + chmod +x $@+ + mv $@+ $@ + git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css rm -f $@ $@+ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \gitweb/gitweb-fcgi.perl new file +51
-0@@ -0,0 +1,51 @@ +#!/usr/bin/perl -w +use strict; +use FCGI; +use CGI; +use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; + +sub usage { + print STDERR "$0 --fcgi-socket=(path|[host]:port) ", + "--cgi-bin=path\n"; + exit 1; +} + +my ($fcgi_sock, $cgi_bin); +GetOptions('fcgi-socket|s=s' => \$fcgi_sock, + 'cgi-bin|c=s' => \$cgi_bin) or usage(); + +usage() unless ($fcgi_sock && $cgi_bin); + +die "FastCGI socket: $fcgi_sock already exists!\n" if (-S $fcgi_sock); +die "CGI executable: $cgi_bin does not exist!\n" if (!-f $cgi_bin); + +# gitweb will exit, make it throw an exception instead: +no warnings qw/once/; +*CORE::GLOBAL::exit = sub { die 'gitweb_exit' }; +use warnings; + +# FCGI will erase the current %ENV; so make sure we save this: +my $gwcfg = $ENV{GITWEB_CONFIG}; + +my $fcgi_req = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, + FCGI::OpenSocket($fcgi_sock, 128), + FCGI::FAIL_ACCEPT_ON_INTR); +while ($fcgi_req->Accept >= 0) { + unless ($ENV{PATH_INFO}) { + # nginx currently fails to set PATH_INFO, + # so we'll do it ourselves + my $pi = $ENV{SCRIPT_NAME}; + $pi =~ s!^/\+!!; + $ENV{PATH_INFO} = $pi; + } + # clear CGI query parameters set inside gitweb so we can reparse + # the %ENV fed to us + CGI::initialize_globals(); + $ENV{GITWEB_CONFIG} = $gwcfg if defined $gwcfg; + do $cgi_bin; + delete $ENV{PATH_INFO}; +} + +END { + unlink $fcgi_sock if (defined $fcgi_sock && -S $fcgi_sock); +}gitweb/gitweb.perl +1
-0@@ -9,6 +9,7 @@ use strict; use warnings; +no warnings qw(redefine); # for FCGI use CGI qw(:standard :escapeHTML -nosticky); use CGI::Util qw(unescape); use CGI::Carp qw(fatalsToBrowser);
PATCH 2/2 instaweb: add support for nginx + FastCGI
In reply to Eric Wongnginx does not support regular CGI
---
Oops, the original patch returned -1 in use_fcgi() instead of 1, which shells don't like :x
Makefile | 5 +++- git-instaweb.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-)
Makefile +4 -1
@@ -690,7 +690,8 @@ gitweb/gitweb.fcgi: gitweb/gitweb-fcgi.perl chmod +x $@+ mv $@+ $@ -git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css +git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css \ + gitweb/gitweb.fcgi rm -f $@ $@+ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -699,6 +700,8 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css -e '/@@GITWEB_CGI@@/d' \ -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \ -e '/@@GITWEB_CSS@@/d' \ + -e '/@@GITWEB_FCGI@@/r gitweb/gitweb.fcgi' \ + -e '/@@GITWEB_FCGI@@/d' \ [email protected] > $@+ chmod +x $@+ mv $@+ $@
git-instaweb.sh +71 -1
112 lines not on this page · raw message
Signature · 1 line
1.5.0.rc0.gc26c8