From 4da8a13614674cae366970c20603dcab7d83e0b1 Mon Sep 17 00:00:00 2001 From: Ricardo Katz Date: Tue, 5 Sep 2023 23:03:57 +0000 Subject: [PATCH] Fix issues on njs and template --- internal/nginx/main.go | 5 ++++- rootfs/etc/nginx/njs/passthrough.js | 6 +++--- rootfs/etc/nginx/template/nginx.tmpl | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/nginx/main.go b/internal/nginx/main.go index e95018e3e..1502ab4da 100644 --- a/internal/nginx/main.go +++ b/internal/nginx/main.go @@ -130,7 +130,10 @@ func NewPassthroughConfigRequest(data interface{}) (status string, err error) { return "NOK", err } - return string(reply), nil + if strings.Contains(string(reply), "NOK") { + return "NOK", fmt.Errorf("fail to reconfigure dynamically") + } + return "OK", nil } // GetServerBlock takes an nginx.conf file and a host and tries to find the server block for that host diff --git a/rootfs/etc/nginx/njs/passthrough.js b/rootfs/etc/nginx/njs/passthrough.js index 2d585a6c2..c2e367937 100644 --- a/rootfs/etc/nginx/njs/passthrough.js +++ b/rootfs/etc/nginx/njs/passthrough.js @@ -81,7 +81,7 @@ function configureWithData(configdata, s) { // Clear method is not working, we should verify with NGX folks //ngx.shared.passthrough.clear(); - ngx.shared.passthrough.set(KEYNAME, JSON.stringify(backends)) + ngx.shared.ptbackends.set(KEYNAME, JSON.stringify(backends)) return OK } catch (e) { @@ -97,7 +97,7 @@ function getBackend(s) { if (hostname == null || hostname == "undefined" || hostname == "") { throw("hostname was not provided") } - let backends = ngx.shared.passthrough.get(KEYNAME) + let backends = ngx.shared.ptbackends.get(KEYNAME) if (backends == null || backends == "") { throw('no entry on endpoint map') } @@ -116,4 +116,4 @@ function getBackend(s) { } } -export default {getConfigStatus, configBackends, getBackend}; \ No newline at end of file +export default {getConfigStatus, configBackends, getBackend}; diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 23c3b9f58..5803725bf 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -37,7 +37,7 @@ load_module /etc/nginx/modules/ngx_http_opentracing_module.so; load_module /modules_mount/etc/nginx/modules/otel/otel_ngx_module.so; {{ end }} -load_module modules/ngx_stream_js_module.so; +load_module /etc/nginx/modules/ngx_stream_js_module.so; daemon off; @@ -761,6 +761,7 @@ http { } } } +} stream { @@ -837,8 +838,9 @@ stream { We want this server to be always running */}} - js_import njs/passthrough.js; + js_import /etc/nginx/njs/passthrough.js; js_shared_dict_zone zone=ptbackends:32m type=string; + server { listen 19090; js_preread passthrough.configBackends; @@ -847,7 +849,8 @@ stream { } {{ if and $all.IsSSLPassthroughEnabled }} server { - {{ buildSSLPassthroughListener $all }} + # TODO: Remove Hardcode + listen 443; ssl_preread on; js_set $ptupstream passthrough.getBackend; proxy_pass $ptupstream;