📜 ⬆️ ⬇️

Compiling and connecting dynamic nginx 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, besides, with the right modules. For this, nginx fits like no other better. And what do you most likely do, especially if you put it for 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 previously worked with Apache2, disappointment awaits you. You can't just take and put a module from the repository and activate it in the console (a2enmod).
Since version 1.9.11, nginx supports dynamic modules. They are not as easy to install as with Apache, but this is not difficult and now we will analyze it.
Of course, there are already ready dynamic modules from the nginx developers themselves, which can be supplied 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 by specifying the required modules, and then changing configs, paths in the system, etc. - you can add a dynamic module to the current nginx installation.
For this we need:


To add modules to the current installation of nginx, we need to know - with what parameters it was assembled. 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 which parameters nginx was installed (including from the repository), you need to type the command
 nginx -V 


The output will 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 its installation into the system,
/ tmp / echo-nginx-module is the path of the Echo module's cloned repository.

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 build and update 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 the dynamic modules will be located in the / etc / nginx / modules folder.

To enable 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):
load_module modules/ngx_http_passenger_module.so;
load_module modules/ngx_http_echo_module.so;


Done! It remains for us to restart the web server and enjoy life with the right modules:
 service nginx reload 


P.S. I understand that for people who know this article - the captain. But for those who have not encountered this and who are frightened by the compilation of software, the article will be useful to add new or interesting modules to nginx without serious consequences.

Source: https://habr.com/ru/post/305466/


All Articles