Fix the nginx cache snippets - I'd missed the file nesting somehow. Tested on a debian:bookworm image with nginx-full installed, checked that we could pull an arbitrary external site, as well as S3, as well as GitLab artifacts. Signed-off-by: Daniel Stone <daniels@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34341>
45 lines
1.2 KiB
Plaintext
45 lines
1.2 KiB
Plaintext
set $proxy_authorization '';
|
|
|
|
set_by_lua $proxyuri '
|
|
local unescaped = ngx.unescape_uri(ngx.var.arg_uri);
|
|
local it, err = ngx.re.match(unescaped, "(https?://)(.*@)?([^/]*)(/.*)?");
|
|
if not it then
|
|
-- Hack to cause nginx to return 404
|
|
return "http://localhost/404"
|
|
end
|
|
|
|
local scheme = it[1];
|
|
local authstring = it[2];
|
|
local host = it[3];
|
|
local query = it[4];
|
|
|
|
if ngx.var.http_authorization and ngx.var.http_authorization ~= "" then
|
|
ngx.var.proxy_authorization = ngx.var.http_authorization;
|
|
elseif authstring then
|
|
auth = string.sub(authstring, 0, -2);
|
|
auth64 = ngx.encode_base64(auth);
|
|
ngx.var.proxy_authorization = "Basic " .. auth64;
|
|
end
|
|
|
|
-- Default to / if none is set to avoid using the request_uri query
|
|
if not query then
|
|
query = "/";
|
|
end
|
|
|
|
return scheme .. host .. query;
|
|
';
|
|
|
|
# Rewrite the location header to redirect back to this server. Do
|
|
# this using lua header filtering to allow for url encoding the original
|
|
# location header for use as a query parameter.
|
|
header_filter_by_lua_block {
|
|
if ngx.header.location then
|
|
ngx.header.location = "/cache?uri=" .. ngx.escape_uri(ngx.header.location);
|
|
end
|
|
}
|
|
|
|
add_header X-GG-Cache-Status $upstream_cache_status;
|
|
proxy_set_header Authorization $proxy_authorization;
|
|
|
|
proxy_pass $proxyuri;
|