1 | set $proxy_authorization '';
|
---|
2 |
|
---|
3 | set_by_lua $proxyuri '
|
---|
4 | unescaped = ngx.unescape_uri(ngx.var.arg_uri);
|
---|
5 | it, err = ngx.re.match(unescaped, "(https?://)(.*@)?([^/]*)(/.*)?");
|
---|
6 | if not it then
|
---|
7 | -- Hack to cause nginx to return 404
|
---|
8 | return "http://localhost/404"
|
---|
9 | end
|
---|
10 |
|
---|
11 | scheme = it[1];
|
---|
12 | authstring = it[2];
|
---|
13 | host = it[3];
|
---|
14 | query = it[4];
|
---|
15 |
|
---|
16 | if ngx.var.http_authorization and ngx.var.http_authorization ~= "" then
|
---|
17 | ngx.var.proxy_authorization = ngx.var.http_authorization;
|
---|
18 | elseif authstring then
|
---|
19 | auth = string.sub(authstring, 0, -2);
|
---|
20 | auth64 = ngx.encode_base64(auth);
|
---|
21 | ngx.var.proxy_authorization = "Basic " .. auth64;
|
---|
22 | end
|
---|
23 |
|
---|
24 | -- Default to / if none is set to avoid using the request_uri query
|
---|
25 | if not query then
|
---|
26 | query = "/";
|
---|
27 | end
|
---|
28 |
|
---|
29 | return scheme .. host .. query;
|
---|
30 | ';
|
---|
31 |
|
---|
32 | add_header X-GG-Cache-Status $upstream_cache_status;
|
---|
33 | proxy_set_header Authorization $proxy_authorization;
|
---|
34 |
|
---|
35 | proxy_pass $proxyuri;
|
---|
36 | # Redirect back to ourselves on 301 replies
|
---|
37 | proxy_redirect ~^(.*)$ /cache/?uri=$1;
|
---|