【问题标题】:Serve content from external server via apache通过 apache 从外部服务器提供内容
【发布时间】:2018-08-05 04:59:20
【问题描述】:

我正在abc.com 运行我的网络应用程序,并使用 apache 作为网络服务器。

我在 SquareSpace 上托管了一些静态页面...例如。 abc.squarespace.com/landing

我想将 apache 配置为在收到对 abc.com/landing 的请求时提供来自 abc.squarespace.com 的内容

我已经在 nginx 中通过使用 proxy_pass 来完成此操作,后端为 abc.squarespace.com 用于位置 /landing。但我不确定如何在 Apache 中执行此操作。在网络上做研究也没有运气。

提前致谢。

【问题讨论】:

  • 猫王的回答解决了你的问题吗?

标签: apache .htaccess reverse-proxy


【解决方案1】:

邮件正文不能包含带有abc.com 的网址,所以我将使用example.comexample.squarespace.com

我相信您正在寻找帧转发。为了实现它,请使用以下步骤:

  1. example.squarespace.com 上,通过 Web 服务器配置设置适当的 HTTP 标头,允许从 example.com 转发帧:

X-Frame-Options: ALLOW-FROM https://example.com/

详细解释请参考https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

  1. 验证Apache mod_proxy_httpexample.com 上启用:

# apachectl -M | grep proxy_http proxy_http_module (shared)

  1. 在 Apache 配置或 .htaccess 文件中设置以下重写规则以提供来自 http://example.squarespace.com/landing 的内容

<IfModule proxy_http_module> RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] RewriteRule ^landing(.*) http://example.squarespace.com/landing [P] </IfModule>

这里的语法与Apache mod_rewrite的语法相同。

【讨论】:

  • RewriteRule ^landing(.*) http://example.squarespace.com/landing$1 [P] 与 $1 一起使用
【解决方案2】:

不确定请求是重定向到 abc.squarespace.com 还是在内部代理呼叫,这是两者的解决方案

重定向: 浏览器将访问 abc.com/landing 并获得 301 重定向,从而将 url 更改为 abc.squarespace.com/landing

将规则添加到 httd.conf 或包含的 vhost 文件:

RewriteEngine on
RewriteRule   "^/landing/(.+)"  "http://abc.squarespace.com/landing/$1"  [R,L]

代理: abc.com > 浏览器下的 abc.squarespace.com 不会认为该页面是从任何下游域提供的。

选项 1: 使用带有 P(proxy) 开关的重写规则

RewriteEngine on
RewriteRule   "^/landing/(.+)"  "http://abc.squarespace.com/landing/$1"  [P]

选项 2: 使用代理密码

ProxyPass "/landing" "http://abc.squarespace.com/landing"
ProxyPassReverse "/landing" "http://abc.squarespace.com/landing"

此外,如果需要,可以指定超时,如果需要通过任何 Internet 代理进行路由,还可以配置 ProxyRemote

良好的参考文献

【讨论】:

  • Squarespace 没有这个功能有点蹩脚
猜你喜欢
  • 1970-01-01
  • 2015-10-02
  • 2012-12-11
  • 1970-01-01
  • 1970-01-01
  • 2014-08-25
  • 2022-10-24
  • 2015-03-30
  • 1970-01-01
相关资源
最近更新 更多