Skip to content

Instantly share code, notes, and snippets.

@kohenkatz
Created March 24, 2014 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohenkatz/9733945 to your computer and use it in GitHub Desktop.
Save kohenkatz/9733945 to your computer and use it in GitHub Desktop.
How to run Dada Mail under nginx

#Dada Mail (or any other CGI) on Nginx

DISCLAIMER: DO NOT rely on this for production (yet)! I'm not done testing it out.

Nginx does not have built in support for traditional CGI applications (of which Dada Mail is one), so it won't work out of the box.

To make a very long story short, here are a Plack wrapper script and nginx configuration that I have found seem to work.

Notes:

app.psgi

  • You will, of course, need to install the appropriate Plack CPAN modules (and be prepared to wait a very long time for the install to complete).
  • I used Starman to run the Plack script, but you can use any Plack-compatible server that you want.
  • Note that the exec_cb => sub { 1 } is extremely important. Without that line, you will have some things that work, but most won't, because the application will think that it is running as the folder name it is in, instead of as the CGI script itself. (In other words, self_url will return "http://lists.example.com/" instead of "http://lists.example.com/dada/mail.cgi".) However, the primary purpose of this line is actually to allow things like fork() to work; it forces the CGI file to be forked and executed instead of compiled into a persistent PSGI app.
use Plack::App::CGIBin;
use Plack::Builder;
use Path::Class qw( file );
my $path = file($0)->absolute->dir;
my $app = Plack::App::CGIBin->new(root => $path, exec_cb => sub { 1 } )->to_app;
builder {
mount "/" => $app; # This will run the app in the root of the web site; change as necessary.
};
server {
server_name lists.example.com;
root /home/example.com/sites/lists.example.com;
location ~* \.psgi$ {
return 403;
}
location ~* \.cgi(/|$) {
fastcgi_split_path_info ^(.+?\.cgi)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Port 443;
proxy_pass http://localhost:5000;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment