Nginx with nginx-auth-ldap

Considering the lack in documentation related to Nginx with the auth-ldap module i decided to write this small post so that everyone can follow simple instructions in order to achieve that.
first of all we should decide to base this guide on ubuntu so the first think is to upgrade the system. We also need to install some required packages and after that we need to download in our home the project of auth-ldap. 

$ sudo apt -y update
$ apt -y upgrade
$ sudo apt-get install -y dpkg-dev git 
$ cd ~ && git clone https://github.com/kvspb/nginx-auth-ldap.git

After that instead of compile nginx from scratch we can rebuild the package from ubuntu.

$ sudo mkdir /opt/rebuildnginx
$ cd /opt/rebuildnginx
$ sudo apt-get source nginx
$ sudo apt-get build-dep nginx

To adjust add the modules into the build, edit the /opt/rebuildnginx/nginx-1.14.0/debian/rules file.
The stable version has multiple Nginx packages available: common, light, fulland extras. When you run apt-get install -y nginx, you’re installing the “full” version.

To adjust add the modules into the build, edit the /opt/rebuildnginx/nginx-1.14.0/debian/rules file.
The stable version has multiple Nginx packages available: common, light, fulland extras. When you run apt-get install -y nginx, you’re installing the “full” version.
The “common” package is the base install upon which the others are built. The “lighter” package, however is in fact lighter than the “common” package due to the use of the –without-* flags.
We’ll simply edit the “full” version to add our modules and we’ll use the full version also installing.

For our example we don’t want all the modules installed so we edit the full_configure_flags in such way

full_configure_flags := \
                        $(common_configure_flags) \
                        --with-http_addition_module \
                        --with-http_dav_module \
                        --with-http_geoip_module \
                        --with-http_gzip_static_module \
                        --with-http_image_filter_module \
                        --with-http_spdy_module \
                        --with-http_sub_module \
                        --with-http_xslt_module \
                        --with-mail \
                        --with-mail_ssl_module \		
		        --add-module=/root/nginx-auth-ldap

Once that’s edited and saved, we can build Nginx!

cd /opt/rebuildnginx/nginx-1.14.0
sudo dpkg-buildpackage -b

Once the build is complete, we’ll find a bunch of .deb files added in /opt/rebuildnginx. We can use these to install Nginx.
We adjusted the “full” package, and so we’ll want to use that build to install Nginx. Looking at the deb files, we’ll see two “full” packages:

cd /opt/rebuildnginx
sudo dpkg --install nginx-full_1.14.0-5_amd64.deb

That step should be done quickly.
Our recompiled Nginx is installed! We can use nginx -V (capital “V”) to see which flags were used during compilation, letting us know which modules are installed.

Spread the word. Share this post!

Leave Comment

Your email address will not be published. Required fields are marked *