diff --git a/controllers/nginx/rootfs/etc/nginx/lua/error_page.lua b/controllers/nginx/rootfs/etc/nginx/lua/error_page.lua index e8a26ee9e6..ca7dc95e83 100644 --- a/controllers/nginx/rootfs/etc/nginx/lua/error_page.lua +++ b/controllers/nginx/rootfs/etc/nginx/lua/error_page.lua @@ -8,17 +8,17 @@ local get_upstreams = upstream.get_upstreams local random = math.random local us = get_upstreams() -function openURL(status) +function openURL(headers, status) local httpc = http.new() + headers["X-Code"] = status or "404" + headers["X-Format"] = headers["Accept"] or "html", + local random_backend = get_destination() local res, err = httpc:request_uri(random_backend, { path = "/", method = "GET", - headers = { - ["X-Code"] = status or "404", - ["X-Format"] = ngx.var.httpAccept or "html", - } + headers = headers, }) if not res then @@ -26,8 +26,9 @@ function openURL(status) ngx.exit(500) end - if ngx.var.http_cookie then - ngx.header["Cookie"] = ngx.var.http_cookie + for k,v in pairs(res.headers) do + ngx.log(ngx.DEBUG, k, ": ", v) + ngx.header[k] = v end ngx.status = tonumber(status) diff --git a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl index d018d4ebb6..c70788d5b7 100644 --- a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl +++ b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl @@ -407,7 +407,7 @@ http { location / { {{ if .CustomErrors }} content_by_lua_block { - openURL(503) + openURL(ngx.req.get_headers(), 503) } {{ else }} return 503; @@ -477,7 +477,7 @@ stream { location @custom_{{ $errCode }} { internal; content_by_lua_block { - openURL({{ $errCode }}) + openURL(ngx.req.get_headers(), {{ $errCode }}) } } {{ end }}