是否可以将 AWS CloudFront 用于 PHP 个文件?

Is it possible to use AWS CloudFront for PHP files?

我正在尝试使用 AWS CloudFront 加载 PHP 文件,例如 index.php

文档说明 -

Create a web distribution if you want to:

Speed up distribution of static and dynamic content, for example, .html, .css, .php, and graphics files. Distribute media files using HTTP or HTTPS. Add, update, or delete objects, and submit data from web forms. Use live streaming to stream an event in real time.

但是,当我将 PHP 文件上传到相关的 CloudFront 存储桶时,它最终会下载并打开文件。如何让我托管 PHP 个文件?

CloudFront 旨在为最终用户提供内容,而不是执行您的代码。您的 PHP 文件将位于 EC2 实例 运行 PHP 和网络服务器(Apache、Nginx)上,然后您可以将其放在 CloudFront 后面以获得好处。然后,这将生成 HTML 供 CloudFront 提供服务。 CloudFront 本身不处理处理,只处理静态 HTML。将 CloudFront 与 S3 结合使用时,它将直接向最终用户提供内容。

我不太确定您在哪里找到该片段,但介绍似乎没有列出。php 对我来说。

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html

Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users.

However, when I upload PHP files to the relative CloudFront bucket

没有 CloudFront 存储桶 这样的东西,因此您可能指的是 S3 存储桶,它在 CloudFront 后面配置为源。

CloudFront 使用动态内容,例如可能由 PHP 生成的内容,但 PHP 站点需要托管在支持它的服务器上 -- 而不是 S3。

You can host a static website on Amazon Simple Storage Service (Amazon S3). On a static website, individual webpages include static content. They might also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts such as PHP, JSP, or ASP.NET. Amazon S3 does not support server-side scripting. (emphasis added)

https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

请参阅 AWS Web Site Solutions 以了解托管涉及静态或动态内容的网站的选项,请记住 PHP 需要支持服务器端脚本和动态内容的解决方案,因此此处并未提供所有解决方案(包括 S3)将满足您的需求...但这些都与 CloudFront 兼容——它只负责 交付 呈现的内容,而不是原始呈现。