Compiling and connecting nginx dynamic modules


    This article will tell you how to compile and install dynamic modules in nginx in its current installation.

    I think many have come across a situation where you need to install a web server, and a good one, moreover, with the right modules. For this nginx fits like no other better. And what are you most likely doing, especially if you put it the first time? Typing
    apt-get install nginx
    или
    yum install nginx
    

    Then you realize that you want to try the module with http2, use the echo module, or add support for processing Ruby scripts by connecting the Passenger module to nginx.
    If you have worked with Apache2 before, you will be disappointed. You can’t just take and put the module from the repository and activate it in the console (a2enmod).
    Since version 1.9.11 nginx supports dynamic modules. They are not installed as easily as with Apache, but it is not difficult and now we will analyze it.
    Of course, there are ready-made dynamic modules from the nginx developers themselves, which can be installed from turnips:
    sudo apt-get install nginx-module-geoip
    

    But here we are talking about modules from third parties.
    In order not to compile nginx from scratch, specifying the necessary modules, and then change the configs, paths in the system, etc. - you can add a dynamic module to the current nginx installation.
    For this we need:
    • The nginx sources that correspond to your version on the server (you can check the version using nginx -v ). Download the source from here .
    • Installed Passenger (as we will add its dynamic module to nginx)
    • Sources of other modules we need that are not in the basic nginx package: Echo module


    To add modules to the current nginx installation, we need to find out with what parameters it was built. If you collect with parameters in which there will be only new modules, nginx will swear and will not allow the use of such a module.
    In order to find out with what parameters nginx was installed (including from the repository), you need to type the command
    nginx -V
    


    The output would be something like this:
    --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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 --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='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
    


    We only need to add the modules we need here:
    --add-dynamic-module=/usr/share/passenger/ngx_http_passenger_module --add-dynamic-module=/tmp/echo-nginx-module --with-http_v2_module
    

    , where / usr / share / passenger / ngx_http_passenger_module is the path to the Passenger module, appears after installing it in the system,
    / tmp / echo-nginx-module is the path of the inclined repository of the Echo module.

    The result is one command:
    ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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 --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='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' -add-dynamic-module=/usr/share/passenger/ngx_http_passenger_module --add-dynamic-module=/tmp/echo-nginx-module --with-http_v2_module
    


    We carry it out.

    It remains to assemble and update the modules for nginx:
    make modules
    sudo make install
    


    After that, your current nginx will be updated, the necessary modules will be added to it, and dynamic modules will be in the / etc / nginx / modules folder.

    To use them in nginx, it remains only to add the following lines to the very beginning of the file in the global nginx config (/etc/nginx/nginx.conf): Done! It remains for us to restart the web server and enjoy life with the necessary modules:
    load_module modules/ngx_http_passenger_module.so;
    load_module modules/ngx_http_echo_module.so;



    service nginx reload
    


    P.S. I understand that for people who know this article is a captain. But for those who have not come across this and who are afraid of compiling software, the article will be useful to painlessly add new or interesting modules to nginx.

    Only registered users can participate in the survey. Please come in.

    Do you use nginx dynamic modules or rebuild it the old fashioned way

    • 72.1% Yes, it's cool and comfortable 75
    • 27.8% No, I like to compile 29

    Also popular now: