Archive

Archive for April, 2010

Nginx and embedded Perl

April 10th, 2010 deepakg Comments

Nginx ships with support for embedded Perl. At the moment execution of Perl code blocks the nginx worker process and therefore anything that might take an indeterminate amount of time to finish (say a DB query) is discouraged.

That said, there could be scenarios where it could come in very handy – like redirecting users to browser-specific static content, generating CAPTCHA – and given Perl’s versatility I am sure several other.

Unlike Apache – where you can load mod_perl as a module, the embedded Perl support in nginx has to be “baked in” at the time of compilation.

Assuming you downloaded nginx-0.7.65, here is how you’ll build it with Perl support:

cd nginx-0.7.65
/configure --with-http_perl_module
make

Things should go smoothly from here, but you might get the following error:

	objs/ngx_modules.o \
	-lcrypt -lpcre -lcrypto -lz \
	-Wl,-E -L/usr/local/lib -L/usr/lib/perl/5.10/CORE -lperl -ldl -lm \
        -lpthread -lc -lcrypt
/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory `/home/deepakg/nginx-0.7.65'
make: *** [build] Error 2

To fix it create a symbolic link – libperl.so, that points to the version of libperl installed on your system:

cd /usr/lib
sudo ln -s libperl.so.5.10.0 libperl.so

You might need to replace libperl.so.5.10.0 with the version of Perl installed on your system. The compilation should now go smoothly. From here you can follow the usage examples off the nginx Wiki

Categories: Uncategorized Tags: