Building Nginx

Written by on Read time: 2 min

Sometimes you may need more than the defaults provide you. That’s why I build Nginx from source, and why you might need or want to do that at some point too.

What are the benefits?

Obviously you wouldn’t want to do it if it didn’t give you some benefits.

Some possible improvements that you might get from building it yourself include:

  • Modules that aren’t included by default
    • Better compression methods
    • Ways to hide the headers that indicate that you’re running Nginx
    • Nicer autoindexing
  • Removing modules you don’t actually need.
  • Newer version of OpenSSL (TLS1.3 support)

External bits

To build nginx, some preparations were necessary. I’m going to be using /usr/local/src for storing all of the source code.

You’ll want to grab the latest versions for:

  • openssl
  • zlib
  • pcre

If you want to download any nginx modules, also download them. I used:

  • More headers module
  • Brotli compression module
  • Fancy index module

Building it

First we need to prepare the things for building. Remember to add the dependencies to the config options. And I’m going to be building nginx to replace the system package, but if you don’t want that, change the paths as well in the following config:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
./configure --prefix=/etc/nginx \
  --sbin-path=/usr/sbin/nginx \
  --modules-path=/usr/lib/nginx/modules \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/run/nginx.lock \
  --with-select_module \
  --with-poll_module \
  --with-threads \
  --with-file-aio \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-http_addition_module \
  --with-http_xslt_module=dynamic \
  --with-http_geoip_module=dynamic \
  --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_auth_request_module \
  --with-http_slice_module \
  --http-log-path=/var/log/nginx/access.log \
  --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 \
  --with-stream \
  --with-stream_ssl_module \
  --with-stream_realip_module \
  --with-stream_geoip_module \
  --with-stream_ssl_preread_module \
  --with-compat \
  --with-pcre=/usr/local/src/pcre-8.44 \
  --with-pcre-jit \
  --with-http_stub_status_module \
  --with-zlib=/usr/local/src/zlib \
  --with-openssl=/usr/local/src/openssl \
  --add-module=/usr/local/src/ngx_brotli \
  --add-module=/usr/local/src/ngx-fancyindex-0.5.1 \
  --add-module=/usr/local/src/headers-more-nginx-module-0.33 \
  --with-debug

Then just make it and install it with make install.