16

I am getting an unknown directive "perl_modules" error when trying to start nginx with the following /etc/nginx/nginx.conf setting:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    perl_modules perl/lib;

    perl_set $subdomain_uppercase 'sub {
        my $r = shift;
        my $subdomain = $r->subdomain;
        $subdomain = uc($subdomain);
        return $subdomain;
    }';

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

I have perl installed:

root@0f0babe794c4:/etc/nginx# perl -v

This is perl 5, version 20, subversion 2 (v5.20.2) built for x86_64- linux-gnu-thread-multi
 (with 92 registered patches, see perl -V for more detail)

and it looks like the module is enabled in my nginx setup:

root@0f0babe794c4:/etc/nginx# nginx -V
nginx version: nginx/1.9.15
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1k 8 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=debian/extra/njs-1c50334fbea6/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed'

Of note, the above includes --with-http_perl_module=dynamic.

Am I missing an extra step to get this perl module enabled so I can set dynamic variables?

1
  • How you installed your nginx? Tell distributive version (debian?) and source of nginx package. Commented Mar 5, 2017 at 16:56

2 Answers 2

12
+50

You install ngx_http_perl_module as dynamic module (--with-http_perl_module=dynamic) so you need to load this module at the beginning of your nginx.conf:

load_module /usr/lib/nginx/modules/ngx_http_perl_module.so

I've used path from your --modules-path option, so check this directory to get exact name of http_perl module file

3
  • thank you, worked perfectly. I added the following to get it working in my /etc/nginx/nginx.conf file: user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; load_module /usr/lib/nginx/modules/ngx_http_perl_module.so; events { worker_connections 1024; } before the http { block from my example above in my original question. Commented Mar 8, 2017 at 16:49
  • Do I have to install this module on ubuntu? I get a 404
    – chovy
    Commented Jul 23, 2022 at 13:28
  • 1
    @chovy If you want to use perl_modules you need to install nginx-module-perl Commented Jul 24, 2022 at 18:38
1

First we need to install the required modules

  • in Ubuntu you would install nginx-module-perl
  • in Centos install nginx-mod-http-perl

I could test on Centos: Centos directly adds the necessary load_module parameter. However, in case it is missing. We can add it according to the comment of Alexander Ushakov.

find the path of ngx_http_perl_module.so using updatedb and locate ngx_http_perl_module.so

load_module /usr/lib/nginx/modules/ngx_http_perl_module.so or wherever the path of the so file is there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.