How to Deploy React App and WordPress on the Same CloudFront Distribution Domain Name with Different Origins and Behaviors?

0

I'm encountering challenges deploying both a React app and a WordPress site on the same CloudFront Distribution domain name while utilizing different origins and behaviors.

Here's my setup:

  • I have a static website hosting domain serving a React app from an S3 bucket with a Bucket website endpoint e.g

http://react-example-site-build.s3-website-us-east-1.amazonaws.com

  • Additionally, I have a WordPress site hosted on another domain. e.g

http://wordpress.example.com

CloudFront Distribution Origins: I've configured the CloudFront distribution with two origins:

  1. The S3 static website endpoint: react-example-site-build.s3-website-us-east-1.amazonaws.com
  2. The WordPress domain: wordpress.example.com

Behaviors: In the CloudFront distribution settings, I've set up six behaviors:

  1. Five behaviors for React app routes origin:
  • /signin
  • /signup
  • /user/*
  • /forget
  • /resetpassword
  1. One default behavior for the WordPress origin:
  • Default(*)
  • Additionally, for any routes not matching the React app routes mentioned above, they will redirect to the WordPress site served from the S3 static endpoint.

Cache Invalidation: To handle updates, I've included the following cache invalidations:

  • /resetpassword
  • /user/*
  • /forget
  • /signin
  • /*
  • /signup

Issues Faced: Despite the configuration, I'm encountering the following issues:

  1. 404 Errors: Initially, I faced 404 errors for React app behaviors** (/signin, /signup, /user/*, /forget, /resetpassword)**. To address this, I added (index.html) as both the Index and Error documents in the S3 Static website hosting configuration. Although this resolved the errors, I still observe 404s in the console.

  2. User Page Display Issue: When navigating to pages under the /user/* route, initially, the content appears but quickly disappears after login.

Request for Assistance:

I seek assistance in understanding if my logic and configuration are correct. If so, why am I encountering these issues? If not, I would appreciate guidance on how to effectively deploy both the React app and WordPress site on the same CloudFront Distribution domain name with distinct origins and behaviors.

Any suggestions or solutions to update my existing distribution configuration would be greatly appreciated.

Thank you for your insights and assistance.

1 Answer
0

Tackling each issue as numbered:

  1. It's not clear whether you fixed the problem here (because you say "this resolved the errors") but then you say "I still observe 404s". Note that CloudFront won't automatically append index.html to a request that ends in a slash (/) - you can add a CloudFront function if you need this behaviour. I'd also check the S3 access logs to see exactly what documents are being retrieved by CloudFront - I suspect that there is a path issue there.
  2. If the content appears and then disappears there is likely some code on the page that is performing a redirect of some sort. You'll need to check in your browser developer console to see what is happening.
profile pictureAWS
EXPERT
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions