大网数据广告活动
服务器运维问答

Dynamically Proxy 3rd party content to https

· 52CE 我爱测

I'm using java and apache and I'm hosting non secure 3rd party content on my secure page and when I share my page on facebook, facebooks tab doesn't display the insecure content. I ran across an article that describes this behavi…

问题原文

原帖链接 · George · CC BY-SA 3.0

I'm using java and apache and I'm hosting non secure 3rd party content on my secure page and when I share my page on facebook, facebooks tab doesn't display the insecure content. I ran across an article that describes this behavior and I'm looking to correct the issue. https://www.tabsite.com/blog/chrome-and-other-browsers-not-showing-insecure-content/

Since my content providers are not providing secure content, my thought was to use apache to proxy my secure URL to the third parties non secure URL.

How would I go about making my proxy dynamic so that I wouldn't have to consistently modify my server image? My initial thought was to prepend the 3rd party URL with my domain

https://images.example.com?url=http://content-provider.com/image/1234.jpg

and parse it with apache rewrite or something, however I'm not sure that is an appropriate solution. I'm looking for some thoughts and suggestions.

How do I use mod_rewrite to rewrite the url to the query parameter?

I tried something writing the following code with no success

https://images.example.com?url=http://content-provider.com/image/1234.jpg

RewriteCond %{QUERY_STRING} ^url=(.*)$ [NC]
RewriteRule (.*)$ %1 [NC,L,R=301]

I was hoping for http://content-provider.com/image/1234.jpg

已采纳解答

原帖链接 · Unbeliever · CC BY-SA 3.0

To do it in a completely generic way would be difficult. In your example you could change the "R=301" flag to "P" (for proxy) and it should work (use the rewritelog to debug if not).

Otherwise you have to have 'some way' of mapping the request URI to a back end server, possibly a rewritemap could help here, but it would depend on how much you know about the real location of the underlying proxied files.

One possible (but very simple) solution, you could split the servers and assign them a letter.

ProxyPass /a/ http://content-provider-a.example.com/
ProxyPass /b/ http://content-provider-b.example.com/
...

And then general URI paths /a/path/to/file/on/provider-a/ etc. But again you have to know all the locations in advance.

If you explain a bit more, then more suggestions may be forthcoming.

Addition information after discussion. First there is some good informatin on mod_rewrite here: Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask

You should also spend time learning about PCRE.

Using the following as our base configuration, here is some explanation:

RewriteMap myquery "fastdbd:SELECT externalURL FROM photo WHERE id = %s"
RewriteRule ^/images/(.*) ${myquery:$1} [P,L]

$1 is a back reference to the string matched in the RewriteRule, the .* inside the brackets. The %s is the argument passed to the RewriteMap, which in this case is the same thing as $1.

A note of caution. Mod_rewrite is not for the fainthearted. It is very complex and you should expect to spend some time working on this.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。