简体   繁体   English

适用于 PHP 托管的 AWS CloudFront

[英]AWS CloudFront for PHP hosting

I'm new to AWS and am having some difficulties understanding CloudFront.我是 AWS 新手,在理解 CloudFront 时遇到了一些困难。 I have started off with one EC2 instance with NGINX, MySQL, and some PHP files within the public folder to expose APIs to the world.我从一个 EC2 实例开始,它在公共文件夹中包含 NGINX、MySQL 和一些 PHP 文件,以向世界公开 API。 Then I was told CloudFront could be used to protect the instance from malicious attacks.然后我被告知 CloudFront 可用于保护实例免受恶意攻击。 I figured CloudFront required an Elastic Load Balancer.我认为 CloudFront 需要一个弹性负载均衡器。 So I created an ELB, one more EC2 instance (two EC2 instances in total), created a "Target group" grouping these two EC2 instances.所以我创建了一个 ELB,另外一个 EC2 实例(总共两个 EC2 实例),创建了一个“目标组”,将这两个 EC2 实例分组。 I also created a S3 bucket, which seemed to be required for CloudFront even though I didn't think I needed one since my app doesn't have any static contents.我还创建了一个 S3 存储桶,CloudFront 似乎需要它,尽管我认为我不需要它,因为我的应用程序没有任何 static 内容。 Now searching through internet, the general idea seemed that the PHP files should live in the EBS of EC2 instances rather than CloudFront S3 bucket since PHP files need to be executed.现在通过互联网搜索,一般的想法似乎是 PHP 文件应该存在于 EC2 实例的 EBS 中,而不是 CloudFront S3 存储桶中,因为需要执行 PHP 文件。 (and that S3 can't execute any files) (并且 S3 不能执行任何文件)

  • In this case, do I need to deploy my PHP files to both EC2 instances?在这种情况下,我是否需要将我的 PHP 文件部署到两个 EC2 实例?
  • How do I make EC2 instances point to the same database so that all data is kept in once place?如何让 EC2 实例指向同一个数据库,以便将所有数据保存在一个位置? Right now, each EC2 instance holds its own MySQL database in its own EBS storage.目前,每个 EC2 实例都在自己的 EBS 存储中拥有自己的 MySQL 数据库。
  • How does the end to end request flow look like?端到端的请求流程是怎样的? eg The client hits CloudFront.例如,客户端点击 CloudFront。 CloudFront talks to ELB. CloudFront 与 ELB 对话。 ELB talks to one of my EC2 instances. ELB 与我的一个 EC2 实例对话。 The EC2 instance connects to the common MySQL database and fetch data. EC2 实例连接到通用 MySQL 数据库并获取数据。 Response data is returned in reverse order.响应数据以相反的顺序返回。

Am I understanding this correclty?我理解这个正确吗?

I figured CloudFront required an Elastic Load Balancer.我认为 CloudFront 需要一个弹性负载均衡器。

ELB is not required to use CF, but it simplifies few things, such as use of HTTPS between CF and your servers. ELB 不需要使用 CF,但它简化了一些事情,例如在 CF 和服务器之间使用 HTTPS。

do I need to deploy my PHP files to both EC2 instances?我需要将我的 PHP 文件部署到两个 EC2 实例吗?

Yes, but this is not done "manually".是的,但这不是“手动”完成的。 Instead it is done usually through the use of user data (or custom AMI) and auto scaling groups.相反,它通常通过使用用户数据(或自定义 AMI)和 Auto Scaling 组来完成。 So you would have to read up on these topics how to do it.所以你必须阅读这些主题如何做到这一点。

EC2 instance holds its own MySQL database in its own EBS storage. EC2 实例在其自己的 EBS 存储中拥有自己的 MySQL 数据库。

Your DB should be outside of your web-servers.您的数据库应该在您的网络服务器之外。 If you want to self-host it, then it would be dedicated instance.如果您想自托管它,那么它将是专用实例。 If you want to use managed solution, then you can migrate your MySQL to RDS MySQL.如果要使用托管解决方案,则可以将 MySQL 迁移到 RDS MySQL。

How does the end to end request flow look like?端到端的请求流程是怎样的?

As you described.正如你所描述的。

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

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