Nginx – How to configure nginx’s embedded Perl to use Perl modules

nginxperl

I have configured nginx to use a specific version of Perl.

$ sudo /opt/nginx/sbin/nginx -V
nginx version: nginx/0.8.54
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46)
TLS SNI support disabled
configure arguments: --with-debug --with-http_ssl_module --with-md5=auto/lib/md5 --with-sha1=auto/lib/sha1 --with-perl=/opt/perl/bin/perl --with-http_gzip_static_module --user=apache --group=apache --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --prefix=/opt/nginx

I created two Perl modules based on EmbeddedPerlMinifyJS: MinifyJS.pm and MinifyCSS.pm which are in the same directory as the nginx.conf file. Inside the http section of the config file I have the following four lines:

perl_require JavaScript/Minifier.pm;
perl_require CSS/Minifier.pm;
perl_require MinifyJS.pm;
perl_require MinifyCSS.pm;

In my server section I have the following:

location ~ \.js$ {
    perl MinifyJS::handler;
}

location ~ \.css$ {
    perl MinifyCSS::handler;
}

When I start nginx, I get an error about "perl_require".

$ sudo /opt/nginx/sbin/nginx
[emerg]: unknown directive "perl_require" in /opt/nginx/conf/nginx.conf:31

So how do I configure nginx to use the embedded Perl?

(BTW, "perl_modules" also throws an unknown directive.)

Best Answer

I saw the answer immediately after posting. You have to add --with-http_perl_module (and possibly --with-perl_modules_path) when running configure.

This was found at EmbeddedPerlModule in the section entitled "Building Module at Compile-time".