Debian – compiling NGINX from source

Install software pre-requisites:

apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev make gcc libgeoip-dev

Get latest nginx from: http://nginx.org/en/download.html

First stop nginx if it already installed then download and unpack the software:

cd /opt
wget http://nginx.org/download/nginx-1.9.11.tar.gz
tar -zxvf nginx-1.9.11.tar.gz
cd ./nginx-1.9.11
mkdir modules
cd modules
git clone https://github.com/FRiCKLE/ngx_cache_purge.git
cd ..

and then there is just one more important step – to customize your server name: http://www.nginxtips.com/customize-nginx-server-name/ but in essence it all boils down to this:

Edit this file right at line #49: src/http/ngx_http_header_filter_module.c

nano -w +49 src/http/ngx_http_header_filter_module.c

Find these lines:

static char ngx_http_server_string[] = "Server: nginx" CRLF;
static char ngx_http_server_full_string[] = "Server:" NGINX_VER CRLF;

Modify those to match these new ones:

static char ngx_http_server_string[] = "Server: YourCustomName" CRLF;
static char ngx_http_server_full_string[] = "Server: YourCustomName" CRLF;

Modify “YourCustomName” as you want. You can place anything there. It could be the name of your website, product, company, etc.

Configure NGINX:

The configuration I have here works on Debian and preserves default directory layouts, provides support for IPv6, SSL, HTTPv2, WebDAV, nginx-cache-purge module and GeoIP:

./configure --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log 
--http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy 
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module 
--with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-ipv6 
--with-http_geoip_module --with-http_v2_module --add-module=$(MODULESDIR)/ngx_cache_purge

Compile and install NGINX:

make && make install

when everything is done verify:

nginx -V

and you shoud get something like that:

nginx version: nginx/1.9.11
built by gcc 4.8.2 (Debian 4.8.2-21)
TLS SNI support enabled
configure arguments: --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf 
--error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid 
--lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log 
--http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy 
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module 
--with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-ipv6 
--with-http_geoip_module --with-http_v2_module

Leave a Reply

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

two × 4 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.