Host multiple static sites on S3 bucket using cloudfront - amazon-s3

I tried to host the two static sites on an S3 bucket and deployed the code on the root folder and sub-folder.
I followed the AWS article and configured but it's not working.
example.com/site2/index.html - is giving a blank page.
example.com/site2/ - is giving example.com site (loading default site1)
I want to serve site1 from the S3 root folder and site2 from the sub-folder.
site1 - example.com
site2 - example.com/site2/
Thanks!

Related

How to force CloudFront CName to handle non-www requests?

I'm new to CloudFront and was wondering how to force it to redirect. In Apache it's just through Virtual Host, but with CloudFront, I'm confused how to do it.
Here is my scenario
NameCheap
CNAME | www | random12345.cloudfront.net (where my site files are)
AWS
ACM - requirement for CloudFront for custom SSL (N.Virginia)
Domain Name: sample.com
Additional Domain Name(s): *.sample.com
CloudFront Distribution
Domain Name: random12345.cloudfront.net
CName: sample.com
*.sample.com
Result
WORKED: https://www.sample.com | www.sample.com
NOT WORKING: sample.com | https://sample.com | http://sample.com
Typing these in the search bar results to Error: This site can’t be reached sample.com’s server IP address could not be found. DNS_PROBE_FINISHED_NXDOMAIN
I attempted to create an S3 bucket to force redirect to https://www.sample.com
but can't create since CNAME www.sample.com is already used for the CloudFront Distribution. Can't use # in CNAME since it is not recommended on root configuration due to its effect on MX records
Thanks a lot.
You have to following step for redirecting non-www domain to www :
Note: www.example.com bucket should have code and example.com will be empty bucket only configuration mention below.
Create example.com S3 bucket.
Go to S3 bucket properties -> Static website hosting then select Redirect request add value as www.example.com
Set Bucket policy and CORS same www.example.com bucket
Create CloudFront for example.com use origin as example.com.s3-website-us-east-1.amazonaws.com not which selection dropdown giving.
Select user *.example.com ACM for https
Then create Route53 Entry for this example.com as A record select respective CloudFront origin for example.com.
This domain is transferred to AWS if you don't want full NS record then only move A record to AWS.
Then you are done.

How to setup DNS for CloudFront distribution with ACM for test and production servers pointing to different directory roots?

I am facing difficulty in serving requests from test.domain.com with the configuration with a combination of AWS Certificate Manager (ACM), AWS EC2 (linux AMI), AWS CloudFront (CF), Google DNS and Apache server.
I have following setup in public_html directory:
I have 2 folders in /var/www/html
prod
test
Objective is to serve requests received from test.domain.com using test directory and the ones received from domain.com using prod directory.
The setup is working fine with acme ssl certificates ie., for production (domain.com), we are using acme SSL certificate and DNS is pointing to Elastic IP and working fine. Even test.domain.com was working
fine with acme ssl setup.
However, I'm trying to switch to ACM. As it works only with CF and ELB (AWS Elastic Load Balancer), created a CF distribution.
Created one CloudFront (CF) distribution pointing to AWS EC2 endpoint with Origin path /test.
Redirected test.domain.com to CF distribution in Google DNS as the domain is registered with them.
With this setup, test.domain.com is also presenting domain.com and not the test server as anticipated.
https.conf has correct DocumentRoot for each ServerName. But, request is not hitting the virtualhost of test server..
whats missing? pls suggest..
You can try below:
Add both domain.com and test.domain.com to CloudFront CNAME list.
ACM certificate which has common name/SAN as domain.com and *.domain.com (or test.domain.com)
In CloudFront cache behavior , whiteist HOST header, this will make sure that when client access domain.com , cloudfront send the same value in host header when contacting origin.
Link:
Forward host header

AWS S3 + Route53: Redirecto S3 bucket not doing anything

I have a domain: mydomain.com.
I've created an A record for www.mydomain.com with an alias targeting the load balancer's DNS and works just fine:
When I hit www.mydomain.com everything works fine.
Now, I want to redirect all requests to mydomain.com to www.mydomain.com (Note the www prefix).
So I created an S3 bucket named mydomain.com with a redirection to www.mydomain.com, and an A record for mydomain.com with an alias targeting the S3 bucket named mydomain.com I just created.
The idea here is to make all requests to mydomain.com to go to my S3 bucket and then get redirected to www.mydomain.com.
But when I go to mydomain.com, the browser just keeps loading forever. No redirection seems to be happening.
All I want is to redirect requests to mydomain.com to www.mydomain.com, how can I make this work? Why is my browser loading forever and not giving any error?

How to host a static webpage on Amazon Lightsail with a wordpress instance?

I have an instance of Wordpress on Amazon Lightsail, Wordpress is installed on a subdomain, I used the Bitnami image that Lightsail offers. I want to host a static page in the main domain, example: "https://www.expample.com". I have tried the solution that gives Bitnami, simply upload the files to the path: / opt / bitnami / apache2 / htdocs / I tried this but if I access with my browser to the main domain nothing appears
I want to solve this and upload a static website that points to this domain.
You should not use the directory /opt/bitnami/apache2/htdocs/ since you're using a WordPress Stack and Apache is configured to serve the content of the directory /opt/bitnami/apps/wordpress/htdocs/ at the root of your domain.
Please visit Bitnami Documentation for WordPress at AWS for more information:
https://docs.bitnami.com/aws/apps/wordpress

Access images from multiple domains hosted in same account

For example I have 5 domains hosted at same server and same account as well (cpanel account)
domain.com : the main domain
domain1.com to domain4.com are addon domains
If I upload an image to domain1.com it can also be access able from other domains as well.
This is the original uploaded image : domain1.com/123.jpg
it can also be access able at : domain2.com/123.jpg
and domain3.com/123.jpg
and so on
or if the image get uploaded before public_html (above the root of main domain) and can be accessible from multiple domains?
Is there any possible way to do this?