I have a domain through godaddy (www.example.com
) and it is hosted on a different server. I also have a static aboutus page that I have in an S3 bucket. How do I link my aboutus page to the main website so that it has a URL of www.example.com/aboutus
? What changes should I make in my DNS settings?
2 Answers
It is not possible to use DNS to point different pages on the same host name at different servers. All the documents on www.example.com
have to be served from the same server. DNS can only point www.example.com
to one IP address. It can't be split up based on pages.
There are however, some things you can do instead.
Use a subdomain
If you want to host some content on a separate server such as an S3 bucket, you could create a subdomain for that separate server. Subdomains are separate host names for DNS. You can point subdomains to different host names using DNS.
For example you could create the subdomain s3.example.com
and point it to the S3 bucket. Then the URL of your "about us" page would be http://s3.example.com/aboutus
.
If the "about us" page were the only thing in the S3 bucket, you could name the file index.html
in the S3 bucket and point the subdomain about-us.example.com
to the S3 bucket. Then the URL for the page would be http://about-us.example.com/
.
Use a reverse proxy
Your main web server could run a reverse proxy to dynamically fetch documents from the S3 bucket and re-serve them itself. It is very common to use a reverse proxy to assign paths on the main domain to content run on different servers or different port numbers.
A reverse proxy is a great solution when the servers are on the same local network. When the two servers are geographically distant, using a reverse proxy can make those requests significantly slower.
For example if your main server is running Apache with mod_rewrite
and mod_proxy
enabled, you could use this configuration to reverse proxy the page:
RewriteRule ^/?about-us http://s3.example.us-west.amazonaws.com/about-us [P]
Then the URL of the page would be http://www.example.com/about-us
I would recommend you check out Netlify for hosting static sites because they have a generous free tier and static sites are their primary focus.
In AWS Console
- Create a bucket
- Name a bucket to be your domain name for easy setup.
- Go to bucket properties
- Go to edit bucket policy
- In text editor, edit a resource key with your domain name after
::
- Go to static web hosting
- Enable a web hosting option
- There is an endpoint link which is used to point your bucket to the domain
In GoDaddy Console
- Go to manage DNS
- Point CNAME of
www
to endpoint you received from the AWS console
🎉🎉🎉 🥂
Reference: https://www.youtube.com/watch?v=zzNlwGaccs4
-
The OP said he already has a website on a server, but just only one page is in a S3 bucket. So the question is not just how to host a whole website in an S3 bucket. Commented Feb 27, 2020 at 23:04
https://www.example.com/
andhttps://www.example.com/aboutus
the DNS is involved in exactly the same way, just to resolvewww.example.com
to some IP addresses. It is then the webserver at this IP address that has to generate the content based on the full URL. So it is a matter of configuring your webserver, maybe with a redirect or a proxy, to fetch the specific page from elsewhere.