Alias www.example.com to the same example.com on AWS - amazon-web-services

I have an EC2 instance and i have setup a domain with route53 and an elastic IP so that my domain is poiting to the same address all the time. However, I have a problem because only https://example.com is working but not https://www.example.com. I know there must be a way to route or to create an alias so that www.example.com redirects me to example.com, but i'm not sure how to do it.

To create alias record for what's called naked Domain. You need to set A record to directly the IP address.
Go to Route53,
Create Record Set
Name: www.example.com
Type: A - IPv4 address
Alias: No
Alias Target: x.x.x.x (<-- your IP address for example.com)
AWS Documentation » Amazon Route 53 » Developer Guide » Configuring Amazon Route 53 as Your DNS Service » Working with Resource Record Sets » Supported DNS Record Types
Route53にNaked Domainを設定する方法〜ELBを利用しない場合〜(How to configure Naked Domain for Route53 ~ (without ELB))

If you want to redirect requests for www.example.com to example.com, you could use S3 Static Website Hosting, and the Redirect Requests option.
In this case, you would create a bucket named www.example.com, and in the Properties for the bucket, enable Static Website Hosting, then select Redirect Requests, and set the Target Bucket or Domain to www.example.com. Be sure to record the Endpoint URL. For example, if you created your bucket in us-west-2 the endpoint would be www.example.com.static-website-us-west-2.amazonaws.com.
Next in Route53, Open the zone for example.com, and create a Record Set. In the Name field, enter www (this field should be followed by example.com), set the Type to CNAME - Canonical Name and Alias to No. Next in the Value field, enter in the Endpoint you recorded from the Static Website Hosting section above. Again, if the domain was www.example.com and hosted in us-west-2, this should be www.example.com.static-website-us-west-2.amazonaws.com.

Related

How to redirect the root domain to a sub domain in AWS route53?

I'm using AWS route53 as my DNS server.
I have an A Record pointing a webserver for the sub-domain www and CNAME for the root "#" subdomain which points to the www sub-domain, so when I try to get mydomain.com or www.mydomain.com I should get the same result and It works fine in Godaddy DNS and NameCheap DNS servers but in route53 the www record works fine but the # doesn't work and I have to type the full www.mydomain.com for me to get the site back.
In this situation, you don't need to include the # symbol when creating record sets for your domain.
According to the docs,
If you're creating a record that has the same name as the hosted zone, don't enter a value (for example, an # symbol) in the Name field.

AWS cloudfront not working with custom domain

I am trying to use cloudfront for static website s3 with my custom domain.
Following are the steps I followed:
1) Setup a s3 bucket (say, example.com) and enabled static website hosting on it.
2) Also setup a s3 bucket (www.example.com) which redirects to example.com.
3) In route 53, added a hosted zone (example.com) and added the record sets.
4) After this, http://example.com works for me.
Now I am trying to add cloudfront to it. I added the following steps:
5) From Amazon Certificate Manager, added a certificate for www.example.com and got it verified (added to Route 53 DNS, it was verified automatically after some time).
6) Created a cloudfront distribution with following settings:
Domain Origin: www.example.com
Origin Protocol Policy: HTTP Only
Alternate Domain Name: www.example.com
SSL Certificate: Selected from ACM
When I try to launch: https://example.com or https://www.example.com, the site doesn't load. http://example.com does load, but I am not sure if cloudfront is actually working on this or not. Also why is https not loading?
To setup the S3 bucket behind the CF distribution WITH SSL you need to:
Setup S3 bucket example.com (Block all public access = off, policy https://d.pr/i/KU1Q4z)
Create certificate in ACM issued at example.com and *.example.com(or specific subdomain at will), validate it
Create CF distribution
Set created CF alternate domain names to: example.com *.example.com (other subdomain here)
Use custom SSL certificate (previously created and validated)
Create/change default origin, to: example.com.s3-website-AWS_REGION.amazonaws.com with origin protocol policy HTTP Only
CF Default origin behaviour should be more-less like this: https://d.pr/i/h6PrG6
In Route 53 set CF A ALIAS for example.com and CNAME for *.example.com (or other subdomain) pointing at CF_DISTRIBUTION_ID.cloudfront.net
you need to go into rt 53 and point the domain at your cloudfront distribution. It won't appear as an option unless you've set the domain as an alternate domain in the distribution settings. Also, that cert won't work for anything except www.example.com, meaning example.com is excluded. you need a cert that includes example.com and www.example.com (or *.example.com to cover all subdomains)

Configure domain on Godaddy to Amazon S3 bucket

I have the static website hosted on S3 which is displaying correctly using the Amazon s3 link.
As per Amazon docs, I created two buckets, example.io & www.example.io. The example.io has the content (files) for the website; the www.example.io bucket is redirecting to the phlo.io bucket.
I am trying to configure Godaddy Apex domain DNS settings to redirect to the S3 bucket. As an example, the domain is http://example.io & I entered the settings in Godaddy domain DNS in the following form:
Type: CNAME
Name: www
value: example.io.s3-website.eu-west-2.amazonaws.com
TTL: 1 hour
However, the website is not displaying on the link http://example.io. How do I configure the apex domain to display the static website?
You can't, sorry...
AWS do not provide an IP Address that you can add as the Apex A Record. This causes issues using S3, CloudFront, ELB, and API Gateway.
If you are using AWS Route53, you can set the Apex A Record as an "alias" to those other services in your AWS account. This is an AWS bespoke service to get around only being able to set an A Record IP Address as the Apex Address.
So you can either move your DNS to AWS, or use a www redirection service. This will provide you with an IP Address which will respond with a redirection to your www.example.io address. People often use services like wwwizer.com to do this for free: http://wwwizer.com/naked-domain-redirect
On further investigation, it turns out that GoDaddy offers http redirection in its DNS service. Here is a guide to setting up naked domain name redirection to the www sub domain: https://help.ghost.org/article/17-custom-domains-using-godaddy
Steps to follow to redirect all traffic from www.yourdomain.com to www.yours3bucket.amazonaws.com
Create a bucket with the same name as your domain name(in this case www.yourdomain.com), make it public and host it.
Go to Godaddy DNS Server and Enter a CNAME Entry with host as www, Points to as www.yours3bucket.amazonaws.com and TTL as default.
(This is to redirect all the traffic to your AWS S3 Bucket, It will only work with www.yourdomain.com and not with yourdomain.com if you do not set a forwarding as mentioned on step 3)
Now also add a 301 forwarding to http://www.yourdomain.com or https://www.yourdomain.com.
(This is to forward yourdomain.com to www.yourdomain.com)

Point www subdomain to naked domain instead of bucket name

I've got a domain name (example.com) which I've purchased through namecheap. The website is a just static site that I recently decided to switch over to S3. Following the instructions on the aws website I've:
Created two buckets: example.com and www.example.com
Configured the example.com bucket to be a static website and placed my files in it.
Configured the www.example.com bucket to redirect to the example.com bucket
Created a hosted zone for my domain
Placed a type A alias for example.com in my hosted zone that points to my example.com bucket
Placed a type A alias for www.example.com in my hosted zone that points to my www.example.com bucket
Taken the nameservers from the NS record in my hosted zone and in namecheap set my domain to use them.
When I go to example.com it works just as expected. When I go to www.example.com it takes me to my website correctly but it shows www.example.com.s3-website.us-east-2.amazonaws.com as the domain. I haven't been able to figure out how to get it to point to www.example.com instead. Where have I gone wrong?
Configured the www.example.com bucket to redirect to the example.com
bucket
You want the actual redirect url configured in S3 to be https://example.com, not the url of your example.com bucket. Just update that and you should be good to go.

Direct traffic from domain.org to domain.com

I am hosting my website on amazon web services. I use a beanstalk application and have an A-record that directs the address www.domain.com to the beanstalk. I also have the same domain but with a .org at the end. I also created an A record that points the domain.org to the same beanstalk application. This works. The problem is that I will buy a ssl certificate for the domain.com and therefore I need the user to be directed to the domain.com when he/she enters domain.org. I tried adding a CNAME record for the domain.org address with the value domain.com. The result is that the user ends up in the correct page but the address in the url bar is domain.org which might cause a problem since the certificate is for domain.com.
DNS cannot do any redirection. That's purely HTTP-level material. You would need to configure your .org vhost to do that, e.g. on apache:
<VirtualHost *:80>
ServerName www.domain.org
RedirectPermanent / http://www.domain.com
</VirtualHost>
Your CNAME is basically pointless. All it does is point a hostname at another hostname, which causes your DNS resolver to fetch the IP of that "another host". It then uses that IP as the IP for the original name. e.g.
domain.org -> CNAME pointer -> domain.com -> a.b.c.d
which then does an HTTP request to the a.b.c.d IP with
Host: domain.org
in the http request header.
You can use Amazon S3 to do this.
Create an S3 bucket called domain.org
Enable Static Web Hosting on the new bucket by choosing "Redirect all requests to another host name"
Set domain.com or www.domain.com as that other domain
If you are using Route53 for your DNS, you can create an Alias record for domain.org to point to your bucket. If you are not using Route53, then create a CNAME to your bucket's public URL.
You can easily do similar things for domain.com -> www.domain.com if you are using Route53.