大网数据广告活动
网站运营与故障问答

Wordpress Reverse Proxy with Cloudfront and S3

· 52CE 我爱测

I have an angular site / web application example.com hosted on Amazon S3 as a static website. This s3 bucket serves as the origin for a cloudfront distribution and it works perfectly. We have an additional requirement of deployin…

问题原文

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

I have an angular site / web application example.com hosted on Amazon S3 as a static website. This s3 bucket serves as the origin for a cloudfront distribution and it works perfectly.

We have an additional requirement of deploying a blog for SEO purposes. I have wordpress instance which I mapped using DNS to blog.example.com

How can I make this www.example.com/blog?

  • All the links on the blog must redirect to www.example.com/blog instead of blog.example.com

  • The address bar should always be displayed as www.example.com/blog

  • All the guides I have gone through require the www.example.com to be hosted via Nginx or Apache. This has to be on S3 + cloudfront.

已采纳解答

原帖链接 · Michael - sqlbot · CC BY-SA 3.0

Easy enough.

CloudFront supports multiple origin servers, and uses path patterns to determine which origin server to forward the requests to... so multiple, independent backend systems, even systems that aren't inside AWS, can all "own" one or more paths under a single hostname, with one of them being the default and owning all the paths not explicitly configured.

This is probably similar to what you have read about Nginx or Apache (and can also be done with HAProxy and others), but the request routing is done by CloudFront, which connects to the appropriate back-end, sends the request, and returns (and possibly caches) the response.

It does not redirect, so the browser address bar never changes.

The caveats:

CloudFront won't strip paths, so /blog* routes requests to bloghost.example.com then bloghost has to have its content under the /blog path, not in the root of the site.

CloudFront forwards very few headers to the origin by default. You can configure it to forward what you need, but every header you forward will reduce your cache hit ratio. There are very sound reasons why this is true, though beyond the scope of this answer. You need to identify which headers wordpress needs, and whitelist them in CloudFront.

You will also need to configure CloudFront to forward query strings and cookies, since, again, it doesn't forward those by default.

See also:

https://stackoverflow.com/a/38709097/1695906

https://serverfault.com/a/729706/153161

https://stackoverflow.com/a/32364600/1695906

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

资料来源与适用范围

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

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

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