}

How to install nginx echo module latest version

Created:

Introduction

Echo module for nginx provides utilities that help testing and debugging of other modules. It could be also useful for production applications, for example:

  • Serve static content from memory
  • wrap the upstream response with custom header and footer
  • merge contents of various nginx locations together

Usage example

In your nginx configuratyion files you will be able to do things like this:

location /hello {
     echo "hello, world!";
}

Step 1: Download the nginx and echo module source code

We are going to download the code from the master branch of the github repository of echo. The we will download the latest compatible version of nginx.

sudo apt-get install git
git clone https://github.com/openresty/echo-nginx-module.git
export ECHO_PWD=$(pwd)/echo-nginx-module
wget 'http://nginx.org/download/nginx-1.11.2.tar.gz'
tar -xf nginx-1.11.2.tar.gz
cd nginx-1.11.2

Step 2: Install requirements

Download all nginx dependencies, so we can compile the source code

sudo apt-get build-dep nginx

We are ready to compile!

Step 3: Compilation

We use --prefix to install nginx under the opt directory, fell free to change this option. If you are using other module, don't forget to add them at the configure parameters!

./configure --prefix=/opt/nginx \
  --add-module=$ECHO_PWD

Check at the output of configure that the echo module was detected (usually you get an error):

configuring additional modules
adding module in /home/leonardo/tmp/echo-nginx-module
 + ngx_http_echo_module was configured

You are ready to make nginx:

make -j$(nproc)
make install

Step 4: Test the echo module

We are ready to test the echo module, add the following location to a site (or the example site):

location /hello {
     default_type text/plain;
     echo hello;
}

Then on the client side:

wget -S --spider localhost/echo

You should get the changed content-type somewhere in the output:

Content-Type: text/plain

You are done!