HTTP Map module no longer in binary or source build?

My issue:
I am trying to do a simple map for the log format (trying to setup for using GoAccess app, but I keep getting an error that the map module can’t be found or the map config is incorrrect. If I comment out the ‘map’ in the config, the nginx -t passes. But fails if I re-add it. I have tried this with both v1.18 (Ubuntu 22.04 binary), v1.24 (Ubuntu 24.04 binary) and v1.28 (source code), but it seems the “ngx_http_map_module” or “http_map_module” is either no longer an option even if specifically asked in the ./configure. It shows it can be disabled, but not enabled.

How I encountered the problem:
Ran the basic “nginx -t” against my code and it keeps spitting out the same error:

nginx: [emerg] unexpected "{" in /etc/nginx/nginx.conf:57
nginx: configuration file /etc/nginx/nginx.conf test failed

Solutions I’ve tried:
Still trying to find one that actually works.

nginx.conf with map entry:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 1024;
        multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        map $time_local $log_time_custom {
            default   "";
            ~^(?P<day>[0-9]{2})/ # Capture day
             (?P<month>[A-Za-z]{3})/ # Capture month
             (?P<year>[0-9]{4}): # Capture year
             (?P<hour>[0-9]{2}): # Capture hour
             (?P<minute>[0-9]{2}): # Capture minute
             (?P<second>[0-9]{2}) # Capture second
             \s(?P<tz_offset>[+-][0-9]{4})$
             "$weekday $month $day $hour:$minute:$second $tz_abbr $year";
        }

        map $time_local $weekday {
            default "";
            ~^(?P<wday>[A-Za-z]{3})/.+$ $wday;
        }

        map $time_local $tz_abbr {
            default "";
            ~^.+ \s(?P<tz>[A-Z]+)$ $tz;
        }

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

My config:

Ubuntu v1.28 configuration (source) - fails on the map module:

./configure \
--with-cc-opt='-g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/nginx-5QYLpr/nginx-1.24.0=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/nginx-5QYLpr/nginx-1.24.0=/usr/src/nginx-1.24.0-2ubuntu7.3 -fPIC -Wdate-time -D_FORTIFY_SOURCE=3' \
--with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now -fPIC' \
--prefix=/usr/share/nginx \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=stderr \
--lock-path=/var/lock/nginx.lock \
--pid-path=/run/nginx.pid \
--modules-path=/usr/lib/nginx/modules \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--with-compat \
--with-debug \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_sub_module \
--with-mail_ssl_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-http_geoip_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_perl_module=dynamic \
--with-http_xslt_module=dynamic \
--with-mail=dynamic \
--with-stream=dynamic \
--with-stream_geoip_module=dynamic
--with-http_map_module

Ubuntu U22 Binary configs

>> nginx -V 2>&1
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 3.0.2 15 Mar 2022
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-niToSo/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_secure_link_module --with-http_sub_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_geoip_module=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-headers-more-filter --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-auth-pam --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-cache-purge --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-dav-ext --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-ndk --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-echo --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-fancyindex --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/nchan --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/rtmp --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-uploadprogress --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-upstream-fair --add-dynamic-module=/build/nginx-niToSo/nginx-1.18.0/debian/modules/http-subs-filter
1 Like

Heya! This seems to be an issue with your NGINX config, not the map module. Curly braces are a special character so NGINX thinks you are starting a new block in the middle of your map directive. Can you try wrapping everything in double quotes? (You might need to remove the comments.)

1 Like