~tomleb/nginx-echo-module

Module that echos back whatever the client sends
Change LICENSE, add SSL support
Add listen directive to specify the listen address

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~tomleb/nginx-echo-module
read/write
git@git.sr.ht:~tomleb/nginx-echo-module

You can also use your local clone with git send-email.

#NGINX echo module

A core module that echoes messages back to the client.

A message consists of any bytes ending with !\r\n.

#Configuration

Syntax: echo { ... }

Default: -

Context: main

Provides the configuration file context in which the echo server directive are specified.

Syntax:

listen address[:port] [ssl];

listen port [ssl];

Default: -

Context: echo

Sets the address and port for IP on which the server will accept requests.

If ssl is specified, then the connection will use TLS 1.2 or TLS 1.3.

Syntax:

ssl_certificate file;

Default: -

Context: echo

Specifies a file with the certificate in the PEM format.

Syntax:

ssl_certificate_key file;

Default: -

Context: echo

Specifies a file with the secret key in the PEM format.

#Example configuration

Here is an example configuration to create an echo server that listens on 0.0.0.0:1965.

load_module /path/to/ngx_echo_module.so;

echo {
  listen 1965 ssl;
  ssl_certificate "/etc/certs/mycert.crt";
  ssl_certificate_key "/etc/certs/mycert.key";
  
}

You can then test the ssl connection with the following command:

openssl s_client -servername localhost -connect localhost:1965

#Build

To build any module, you need the source code of nginx. On Archlinux, you can install the package nginx-src.

Then, you can run the following command in the source directory of nginx.

export MY_MODULE=<path to module>
eval "./configure --add-dynamic-module=$MY_MODULE $(nginx -V 2>&1 >/dev/null | grep  -o '\--with.*')"

make modules

Note that we used the compilation flag of the installed nginx. If building nginx from source, it's a better idea to use that nginx' flag instead.

#License

See LICENSE file. Note that some SSL code was copied and modified from the NGINX source, so that's why I am using their license. I am not a lawyer.

#Contribution

This module is more for exploration and fun, but I'll be glad to accept patches.

Make sure to follow NGINX's incredibly good Development Guide.