Hello. I have tried to build 3rdparty dynamic module for nginx (https://github.com/SpiderLabs/ModSecurity-nginx), but after configuring (./configure --with-compat --add-dynamic-module=/opt/custom/modsecurity-nginx-v1.0.1) and building (make -j8) openresty says modsecurity is not binary compatible: nginx: [emerg] module ... is not binary compatible in /opt/openresty/nginx/conf/nginx.conf:1
How should I configure openresty for dynamic modules usage? Both source and installed versions of openresty are equal.

    3 months later

    Hello,

    I had the same problem and I was searching for a long time without find anything. Luckily I've found a solution, and is to use the same compilation options of the installed version.

    For example, I've installed openresty from the repository. To compile the module I've downloaded the module and placed it on same openresty src folder, then I've run this commands:

    # Export the LUAJIT variables to avoid errors
    /tmp/openresty-1.19.3.1/bundle/nginx-1.19.3# export LUAJIT_LIB="/usr/local/openresty/luajit/lib/"
    /tmp/openresty-1.19.3.1/bundle/nginx-1.19.3# export LUAJIT_INC="../LuaJIT-2.1-20201027/src/"
    
    # Getting compile options.
    COMPILEOPTIONS=$(openresty -V 2>&1|grep -i "arguments"|cut -d ":" -f2-)
    
    # Configure the compilation using the same options and add the geoIP2 module
    eval ./configure $COMPILEOPTIONS --add-dynamic-module=../../modules/ngx_http_geoip2_module
    
    # Compile the modules
    make modules
    
    # Copy the modules to desired folder and enjoy!
    cp objs/ngx_http_geoip2_module.so /usr/local/openresty/nginx/modules/

    The only tradeoff is that you need to install openresty on the machine that you plan to build the modules, but at least is working. I've compiled four modules (GeoIP2, PageSpeed, ModSecurity and Brotli) and at least three of them are working (I've not tested the PageSpeed module yet, but for sure that also is working).

    I'll create an entry on my blog, because surely is usefull for someone else.

    Best regards

    4 days later

    use bundle to compile the so, not only the nginx

      Hello,

      I had problems and that is why I have decided to use the Nginx folder.

      1. The first was that configure in bundle with the openResty compile options fails because it tries to find the modules in the upper folder:
        adding module in /tmp/openresty-1.19.3.1/../ngx_devel_kit-0.3.1
        ./configure: error: no /tmp/openresty-1.19.3.1/../ngx_devel_kit-0.3.1/config was found
        ERROR: failed to run command: sh ./configure --prefix=/usr/local/openresty/nginx/nginx \...
      2. The second is because the Bundle doesn't allow to compile just the modules (make modules).

      Also I have tried in several ways to build it from bundle using just the basic options and I always get the "is not binary compatible" error. The only way to made it works was using the Nginx folder.

      It works, so is enough for me 😉

      Best regards

      3 months later

      @Danixu thank you for posting this. You got me on the right track.

      I stumbled upon the fact that you don't have to have OpenResty installed. All you have to do is run ./configure in the top level OpenResty source dir which will build LuaJIT right in the OpenResty source dir. Then you can export the following:

      export LUAJIT_LIB='/root/build/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/lib'
      export LUAJIT_INC='/root/build/openresty-1.19.3.1/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.1'

      Change the root path to your OpenResty source dir of course. Then run the compile as shown above. This has worked for me so far with ModSecurity.

        Write a Reply...