匿名 Amazon public URL,在 Nginx 上使用脚本解码

Anonymize Amazon public URL, decode using a script on Nginx

我一直在想是否可以匿名化 public URL。当用户使用这个匿名 public URL 发出请求时,让 Nginx 解码、获取并提供 URL。

示例

Public URL http://amazon.server.com/location/file.html

匿名化URLhttps://amazon.server.com/09872340-932872389-390643289/983724.html

Nginx 将 09872340-932872389-390643289/983724.html 解码为 location/file.html

添加下面的图片以进一步说明。 Nginx 有反向解码逻辑,而 Remote Server 有匿名化逻辑 URL。

问题 我只需要知道 Nginx 如何解码匿名 URL? Nginx 得到了匿名 URL 请求。必须有一种方法来解码它。

为 URL 定义匿名化?您可以使用任何与 URL 缩短器相同的方法,例如 http://bitly.com。但这并不是真正的匿名,因为在缩短的 URL 和目标 public url 之间存在明确的映射。如果您基于每个用户进行此操作,仍然存在映射,但它是基于用户的。

看起来你所建议的是上述方案的变体,而不是通过重定向将用户发送到目标 URL 你希望你的服务器实际获取内容并且 return 给用户。您需要了解 public URL 中的链接内容,例如样式表和图像,并相应地进行调整。许多标准代理都内置了这种功能。另请查看

https://github.com/jenssegers/php-proxy

http://search.cpan.org/~book/HTTP-Proxy-0.304/lib/HTTP/Proxy.pm

如果您打算建立自己的网站,这些可以作为基础。

我认为你想在这里做的事情与我过去回答过的另一个问题有点相似,对于客户端的每个请求,你实际上想在后台向两个不同的上游发出两个请求(第一个到能够解码 URL 的上游,第二个实际获取所述解码的 URL),但是,当然,只有 return 个结果。

https://serverfault.com/questions/202011/nginx-and-2-upstreams/485044#485044

如 serverfault 中所述,您可以使用 error_page to process another request, after the first one is complete. You could then use $upstream_http_ to make the subsequent request based on the original one, for example, using $upstream_http_location

您可能还想查看 X-Accel-Redirect header,在 proxy_ignore_headers 的上下文中介绍。

这是对更新问题的回答:

Question All I need to know is how would Nginx decode anonymized URL? Nginx got anonymized URL request. There has to be a way to decode it.

Nginx 会向脚本发出请求,例如,通过 proxy_pass or fastcgi_pass

脚本可以解码 URL 并通过具有 302 Found HTTP 状态的 Location HTTP 响应 Header 提供实际的 URL。

Nginx 然后将解码后的 URL 存储在 $upstream_http_location variable. It could subsequently be used in another proxy_pass et al within a named location @named, to which you could redirect the processing of the original request from the user through error_page 302 = @named.

总而言之,每个用户请求都会在 nginx 中处理两次,但对用户来说都是透明的——他们只是通过原始 URL 接收资源,所有重定向都在内部完成在 nginx 中。