简体   繁体   中英

Cloudfront + EC2 + PHP

I'm currently running an angular 8 app from a S3 bucket that references a php server on an ec2 mid tier, to pull data from a RDS MySQL database. All works well but I needed to ensure https access for security, so I added Cloudfront over the endpoints to forward all http requests to https. It works fine for S3 and php for static content, but when providing query strings (after?) to the php calls, cloudfront returns a 502 error even after specifying 'Query String Forwarding' in the Behaviour config setting for Cloudfront.

Examples...

abcdefg.cloudfront.net/api/get/getApplications.php works fine and returns a list of all applications.

abcdefg.cloudfront.net/api/get/getApplications.php?ApplicationId=1 should return a single row but has this in the header...

KEY             VALUE
Content-Type    text/html
Content-Length  1033
Connection      keep-alive
Server          CloudFront
Date            Fri, 24 Apr 2020 09:32:35 GMT
X-Cache         Error from cloudfront
Via             1.1 74e2a59e06d5b7556eb510403eacd42e.cloudfront.net (CloudFront)
X-Amz-Cf-Pop    LHR61-C2
X-Amz-Cf-Id     _yb_GEE24tZXcmohUcNwCqwT54FExprLfepS1R7-7kHLXXjLpHqTow==

Just to be clear executing the php from the origin machine works fine. eg ec2-machine.eu-west-2.compute.amazonaws.com/api/get/getApplications.php?ApplicationId=1

Please can anyone think of anything I may be missing or advise on an alternative approach as I've searched the AWS documentation and online and cant find a solution?

Thanks

After not changing anything, the php link began to work. It seems the cloudfront configs take a few our to become available if the origin code is amended.

Answering my own question:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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