Setting Up a Cloudflare Domain for an Amazon Lightsail Website David Morgan October 18, 2024 GuidesAmazon Lightsail offers an affordable and easy way to deploy virtual servers, and pairing it with Cloudflare provides extra security, speed, and DNS management. If you’ve purchased your domain through Cloudflare and want to point it to an instance hosted on Amazon Lightsail, this guide will help you seamlessly connect them using Cloudflare nameservers. Below is a step-by-step process for setting up DNS, making changes in Cloudflare, and ensuring everything is ready for the world to see.Step 1: Setup Your Amazon Lightsail InstanceFirst, log in to your Amazon Lightsail account and create an instance.Go to the Amazon Lightsail Console.Click on Create Instance.Choose your preferred instance location, instance image (e.g., Linux/Ubuntu), and select an appropriate plan.Once you’ve created the instance, Lightsail will assign a static public IP. It is crucial to attach a static IP to ensure that the server’s IP address doesn’t change if it’s restarted.You’ll need the static server IP to create the records on CloudFlare.Once you have the static IP address, write it down, as you’ll need it when configuring DNS in Cloudflare.Step 2: Point Your Domain to Amazon Lightsail Using CloudflareSince your domain is registered with Cloudflare, it will use Cloudflare’s nameservers by default. To connect your domain (e.g., example.com) to your Lightsail instance:Log in to your Cloudflare Dashboard.Select your domain (e.g., example.com).Go to the DNS tab to manage DNS settings.You’ll need to create two DNS records:A Record:Name: @ (This means the root domain, e.g., example.com)IPv4 Address: Enter your Lightsail static IP address (e.g., 192.0.2.1)TTL: AutoProxy Status: Keep it Proxied (orange cloud) for Cloudflare security and caching, or DNS only (grey cloud) if you prefer direct traffic without Cloudflare’s CDN.Example:Type: A Name: @ Content: 192.0.2.1 TTL: Auto Proxy Status: ProxiedCNAME Record (for www subdomain):Name: wwwTarget: example.comTTL: AutoProxy Status: ProxiedExample:Type: CNAME Name: www Content: example.com TTL: Auto Proxy Status: Proxied The 2 most important records are A and CNAME. The IPv6 IP record is optional.Important tip: When creating the Let’s Encrypt SSL/TLS certificates, disable the proxy status for the records above. You can enable the proxies after setting up the certificates. Step 3: Configure SSL for Secure ConnectionOne of the advantages of using Cloudflare is their free SSL/TLS feature. To set it up:In your Cloudflare dashboard, navigate to the SSL/TLS tab.Choose Full or Full (Strict) mode to enable end-to-end encryption between Cloudflare and your Lightsail server. Ensure that you’ve set up an SSL certificate on your Lightsail server if using Full (Strict).You can use Certbot or Lightsail’s built-in certificate to generate a certificate for SSL on your instance.Step 4: Update Firewall Settings on Amazon LightsailTo ensure your Lightsail instance is accessible, adjust its firewall settings to allow HTTP and HTTPS traffic:Go to your Lightsail instance management page.Click on the Networking tab.Under Firewall, add rules for:HTTP (Port 80)HTTPS (Port 443)Step 5: Test Your SetupWait for the DNS changes to propagate. This can take anywhere from a few minutes to 24 hours, though it usually updates quite quickly.To verify your setup:Open a browser and go to http://example.com and https://example.com. Both should point to your Lightsail instance and load your website.You can also use tools like What’s My DNS to check if the DNS records have propagated globally.Step 6: Set Up Page Rules (Optional)Cloudflare’s Page Rules can help enhance your website’s performance and security. A common rule is redirecting all www traffic to the root domain.In Cloudflare, go to the Page Rules tab.Create a new rule with the following settings:URL: www.example.com/*Forwarding URL: Redirect to https://example.com/$1 (Make sure it’s a 301 – Permanent Redirect). Connecting a Cloudflare-bought domain to an Amazon Lightsail instance provides an efficient way to host your website with all the benefits of Cloudflare’s security and speed optimizations. By following these steps, you can ensure your domain is correctly pointed to your Lightsail server while enjoying Cloudflare’s DNS management, SSL, and additional features.Feel free to revisit these instructions whenever you need to adjust any settings or add new domains!Leave a Reply Cancel ReplyYour email address will not be published.CommentName* Email* Website Save my name, email, and website in this browser for the next time I comment. Δ