lots of tech info here

How to forward Nginx Perl requests to Apache mod_cgi

Nginx with mod_php

Nginx has an experimental Perl module which doesn't work well for multiple/concurrent Perl requests. Its still in development. For production use, I personally think its safer to forward all Perl requests to Apache's mod_cgi or mod_perl. Lets get it configured. Nginx is running on port 80. Apache 2.2 is installed and running on port 8080. To enable Perl requests .pl and .cgi be served in Apache:

Edit /etc/apache2/apache2.conf and make sure these lines are present:

AddHandler cgi-script .pl .cgi
Options FollowSymLinks +ExecCGI

Restart Apache:

  sudo /etc/init.d/apache2 restart

Now, configure Nginx to forward requests from Perl scripts to Apache.

Edit /etc/nginx/apachemod.conf and make it look like this:

location ~ .*\.(php|pl|cgi)$ {
    proxy_pass         http://127.0.0.1:8080;
    proxy_redirect     off;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    client_max_body_size       10m;
    client_body_buffer_size    128k;

    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;

    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
}

Restart Nginx:

  sudo /etc/init.d/nginx restart

See if Nginx serves Perl pages. Create a simple Perl script called sayhello.pl under DOCUMENT_ROOT with these contents:

#!/usr/local/bin/perl
print "Content-type: text/html\\n\\n";
print "hello from Nginx to Apache";

And navigate to http://imacster.com/sayhello.pl to see if it works.

Nginx with mod_php

Updated on 01 Jul 2009 {Created on 04 Jul 2009}

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.

Share this with Others

Subscribe

Tags