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:
- The S3 static website endpoint: react-example-site-build.s3-website-us-east-1.amazonaws.com
- The WordPress domain: wordpress.example.com
Behaviors:
In the CloudFront distribution settings, I've set up six behaviors:
- Five behaviors for React app routes origin:
- /signin
- /signup
- /user/*
- /forget
- /resetpassword
- One default behavior for the WordPress origin:
- 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:
-
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.
-
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.