You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: Upstream module example
Upstream example
- derived from github.com/gabihodoroaga/nginx-upstream-module and NGINX ngx_http_upstream_keepalive_module.c
Simply replaces peer functions with passthrough versions, i.e., proxies
traffic through this module to originally configured upstream functions.
Useful as a guide and example, but does not add load balancing
algorithms.
---------
Co-authored-by: Matthew Yacobucci <[email protected]>
@@ -150,3 +151,76 @@ The following embedded variables are provided:
150
151
### Caveats
151
152
152
153
This module only supports IPv4.
154
+
155
+
## UPSTREAM - Example upstream / load balancing module for HTTP
156
+
157
+
This module simply proxies requests through a custom load balancer to the previously configured balancer. This is for demonstration purposes only. As a module writer, you can start with this structure and adjust to your needs, then implement the proper algorithm for your usage.
158
+
159
+
The module replaces the `peer` callback functions with its own, logs, and then calls through to the originally saved `peer` functions. This may look confusing at first, but rest assured, it's intentionally not implementing an algorithm of its own.
160
+
161
+
### Attributions
162
+
163
+
This module was converted from https://github.com/gabihodoroaga/nginx-upstream-module and also highly inspired by the same techniques used in NGINX source: `ngx_http_upstream_keepalive_module.c`.
4. Add the `load_module` directive to your configuration.
215
+
```
216
+
load_module "modules/libupstream.so";
217
+
```
218
+
219
+
5. Add the example `server` and `upstream` block from the example above.
220
+
221
+
6. Reload NGINX.
222
+
```
223
+
nginx -t && nginx -s reload
224
+
```
225
+
226
+
7. Test with `curl`. Traffic should pass to your listener on port 8081 (this could be another NGINX server for example). With debug logging enabled you should notice the upstream log messages (see the source code for log examples, prefixed with "CUSTOM UPSTREAM").
0 commit comments