Home | Catalogue | Robert's Blog
Last Updated: [2023-03-29 Wed 07:06]
When developing a new solution that utilises Nginx, you will often end up at the Nginx documentation. From time to time, you'll find that configuration element you need, but then the following line will grab your attention at the top of the page:
This module is not built by default, it should be enabled with the
--with-some_extra_module
configuration parameter.
If you ever see this message in the documentation and wonder if it
has been included in the build of Nginx you're using, you can check the
version output of Nginx (nginx -V
) which
includes a list of configuration parameters used at build time.
Easy as that…
…ok, if you've actually tried this, you'll know that's not optimal. That's difficult to read. It's impossible to grep, and even if you could, the configuration options are on one line.
A bit of Bash magic is needed here:
nginx -V 2>&1 | sed -e 's/\ -/\n-/g'
That is much nicer, you can even pipe that output even further into grep and check if an individual module is installed. So for example, if you want to check the http_v2 module is available, you could run:
nginx -V 2>&1 | sed -e 's/\ -/\n-/g' | grep http_v2
So what does the first part of that one-liner do? Well, let's split it into its two parts:
nginx -V 2>&1
- This runs
Nginx's version output, but the 2>&1
command forwards the stderr output
to stdout, which can be manipulated and greped.
sed -e 's/\ -/\n-/g'
- This will look
for any dash ( -
) with a space before it,
and replace it with a new line and a dash. This puts each module onto a
new line for easier reading and more importantly, make it grepable.
DISCLAIMER: The information provided on this website is generated from my own notes and is provided "as is" and without warranties. Robert Ian Hawdon can not be held responsible for damages caused by following a guide published on this site. This website contains links to other third-party websites. Such links are provided as convienice of the reader. I do not endorce the contents of these third party sites.