热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

匿名化Amazon公共URL,使用Nginx上的脚本进行解码-AnonymizeAmazonpublicURL,decodeusingascriptonNginx

IhavebeenwonderingifitspossibletoanonymizepublicURL.Whenusermakesarequestwiththisa

I have been wondering if its possible to anonymize public URL. When user makes a request with this anonymized public URL, let Nginx decode, fetch and serve the URL.

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

Example

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

公共URL http://amazon.server.com/location/file.html

Anonymized URL https://amazon.server.com/09872340-932872389-390643289/983724.html

匿名网址https://amazon.server.com/09872340-932872389-390643289/983724.html

Nginx decodes 09872340-932872389-390643289/983724.html to location/file.html

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

Added image below for further clarification. Nginx has a reverse logic to decode, whereas Remote Server has the logic to Anonymize URL.

添加了下面的图片以进一步说明。 Nginx具有解码的反向逻辑,而远程服务器具有匿名URL的逻辑。

enter image description here

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如何解码匿名URL? Nginx获得了匿名URL请求。必须有一种方法来解码它。

3 个解决方案

#1


1  

This is an answer to the updated question:

这是对更新后问题的回答:

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如何解码匿名URL? Nginx获得了匿名URL请求。必须有一种方法来解码它。

Nginx would make a request to a script, e.g., either through proxy_pass or fastcgi_pass et al.

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

The script could decode the URL and provide the actual URL through a Location HTTP Response Header with a 302 Found HTTP Status.

该脚本可以解码URL并通过具有302 Found HTTP Status的Location HTTP Response Header提供实际的URL。

Nginx would then have the decoded URL stored in the $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存储在$ upstream_http_location变量中。它随后可以在命名位置@named内的另一个proxy_pass等中使用,您可以通过error_page 302 = @named将用户的原始请求的处理重定向到该位置。

In all, each user request would be processed twice within nginx, but it'll all be transparent to the user -- they simply receive the resource through the original URL, with all redirects being done internally within nginx.

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

#2


1  

Define Anonymize for a URL? You can use any of the same methods as URL shortners such as http://bitly.com. But that is not truely anonymous since there is a definite mapping between the shortened URL and the target public url. If you make this per user based there is still a mapping but it is user based.

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

Looks like what you are suggesting is a variation on the above scheme where instead of sending the user to the target URL via a redirect you want the your server to actually fetch the content and return to the user. You need to be aware of the linked content in the public URL such as style sheets and images and adjust them accordingly. Many of the standard proxies has this kind of functionality built in. Also take a look at

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

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

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

If you are planning to build your own these can serve as a base.

如果您打算自己建造这些可以作为基础。

#3


1  

I think what you want to do here is somewhat similar to another question I've answered in the past, where for each request by the client, you effectively want to make two requests to two different upstreams under the hood (first one to an upstream capable of decoding the URL, second one to actually fetch said decoded URL), but, of course, only return one result.

我想你想在这里做的有点类似于我过去回答的另一个问题,对于客户的每个请求,你实际上想要向引擎盖下的两个不同的上游发出两个请求(第一个到上游)能够解码URL,第二个能够实际获取所述解码的URL),但是,当然,只返回一个结果。

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

As mentioned on serverfault, you could use 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.

正如在serverfault上提到的,在第一个请求完成后,您可以使用error_page处理另一个请求。然后,您可以使用$ upstream_http_根据原始请求生成后续请求,例如,使用$ upstream_http_location。

You might also want to look into X-Accel-Redirect header, introduced in this context at proxy_ignore_headers.

您可能还想查看在此上下文中在proxy_ignore_headers中引入的X-Accel-Redirect标头。


推荐阅读
author-avatar
郭建将_683
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有