简体   繁体   English

如何将域*子目录*(不是子域)指向 AWS EC2 实例

[英]How to point a domain *subdirectory* (not subdomain) to AWS EC2 Instance

I have two EC2 Instances on AWS.我在 AWS 上有两个 EC2 实例。 I can point my main domain name (sample.com)to one instance in Route 53. but how can I point another domain (sample.com/blog) to another EC2 Instance?我可以将我的主域名 (sample.com) 指向 Route 53 中的一个实例。但是如何将另一个域 (sample.com/blog) 指向另一个 EC2 实例?

For this behaviour you cannot use just Route 53 as subfolders are not part of DNS resolution.对于这种行为,您不能只使用 Route 53,因为子文件夹不是 DNS 分辨率的一部分。

There are many solutions you could use but the most common for a website are using either CloudFront or an ALB to use path based routing.您可以使用许多解决方案,但最常见的网站是使用 CloudFront 或 ALB 来使用基于路径的路由。

CloudFront CloudFront

With this solution you would put CloudFront in front of your domain (Route 53 will route to a CloudFront distribution.使用此解决方案,您可以将 CloudFront 放在您的域前面(Route 53 将路由到 CloudFront 分配。

A forwarded location is known as an origin, therefore you would create an origin for each of the target hosts.转发的位置称为源,因此您将为每个目标主机创建一个源。

The routing mechanism within CloudFront would be the behaviour, with a default behaviour used to forward to your default host. CloudFront 中的路由机制将是行为,默认行为用于转发到您的默认主机。

You would then create an additional behaviour based on the path pattern of the domain that you would want to be routed to the other origin (eg /blog*).然后,您将根据您希望路由到其他源(例如 /blog*)的域的路径模式创建附加行为。

More information about this option is available in the Can I use a single CloudFront web distribution to serve content from multiple origins using multiple behaviors?有关此选项的更多信息,请参阅我可以使用单个 CloudFront web 分配来使用多种行为提供来自多个来源的内容吗? document.文档。

Application Load Balancer应用程序负载均衡器

With this option your Route 53 record would forward to an ALB.使用此选项,您的 Route 53 记录将转发到 ALB。

You would create a target group for each EC2 instance, and then register this hosts within the target group.您将为每个 EC2 实例创建一个目标组,然后在目标组中注册这些主机。

Within the listener in the ALB you would forward all traffic by default to one fo your target groups, then add an additional rule to the listener based on path patterns to forward to the other target group when appropriate.在 ALB 的侦听器中,默认情况下您会将所有流量转发到目标组中的一个,然后根据路径模式向侦听器添加附加规则,以便在适当时转发到另一个目标组。

More information is available within the Advanced Request Routing for AWS Application Load Balancers blog post. AWS 应用程序负载均衡器的高级请求路由博客文章中提供了更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM