Skip to main content

Deploying a Static Website to Free Hosting with a Custom Subdomain: A Tutorial

This tutorial covers the process of deploying a static website to free hosting services using a custom subdomain, including DNS setup and website configuration. Learn how to get your static website online quickly and securely.

Written by Mayank Baswal

Founder of is-cool-me · DNS & Platform Infrastructure

Mayank Baswal maintains the is-cool-me platform and writes technical guides focused on DNS configuration, subdomain infrastructure, SSL troubleshooting, deployment workflows, and platform reliability.

Reviewed by is-cool-me Technical Review
## Introduction Deploying a static website to free hosting with a custom subdomain is an essential skill for developers looking to showcase their projects or prototype ideas without incurring significant costs. Static websites, which do not require server-side rendering or database connections, can be efficiently hosted on platforms that offer free hosting services with custom subdomains. One such platform is is-cool-me, which allows developers to host their static websites on subdomains like myproject.is-pro.dev. This guide will walk you through the process of deploying a static website to such a platform, covering the setup of a custom subdomain, DNS configuration, and deployment of your website. The motivation behind choosing free hosting with a custom subdomain for static websites is multifaceted. Firstly, it offers a cost-effective solution for developers who are just starting out or working on personal projects. Secondly, it provides a professional-looking URL that can be shared with potential clients or employers, enhancing the credibility of the project. Lastly, the process of setting up a custom subdomain and deploying a static website helps developers understand the basics of web development, DNS configuration, and version control, which are invaluable skills in the industry. ## Prerequisites Before you begin deploying your static website to free hosting with a custom subdomain, there are several prerequisites you need to fulfill. Firstly, you should have a static website ready. This could be a simple HTML, CSS, and JavaScript project, or it could be a more complex static site generated by tools like Jekyll, Hugo, or Next.js. Secondly, you need to have an account on the is-cool-me platform, which will provide you with the free hosting and custom subdomain. If you haven't already, sign up for an account and familiarize yourself with the dashboard. Additionally, you should have a basic understanding of Git, as most free hosting platforms use Git for deploying and updating websites. If you're new to Git, taking a few hours to learn the basics of Git commands like `git init`, `git add`, `git commit`, and `git push` will be beneficial. Lastly, having a code editor or IDE and a terminal or command prompt is necessary for executing commands and editing configuration files. ## Step-by-step instructions Here's a step-by-step guide to deploying your static website to free hosting with a custom subdomain: 1. **Create a new repository** on your is-cool-me account for your static website. This will be the central location for your website's files. 2. **Initialize a Git repository** in your local project directory using `git init`. 3. **Add your website files** to the Git repository using `git add .`, followed by `git commit -m "Initial commit"`. 4. **Link your local repository** to the is-cool-me repository using `git remote add origin https://git.is-cool-me/myproject/myproject.git`, replacing "myproject" with your actual project name. 5. **Push your changes** to the is-cool-me repository using `git push -u origin master`. 6. **Configure your custom subdomain** on the is-cool-me dashboard. This typically involves specifying the subdomain name (e.g., myproject.is-pro.dev) and the repository that contains your website. 7. **Set up DNS records** if necessary. For most cases, is-cool-me will handle the DNS configuration for you, but in some scenarios, you might need to manually configure DNS records to point to is-cool-me's servers. ## Configuration deep-dive Configuring your static website for deployment involves several key settings. The first is specifying the build command, which is often unnecessary for purely static sites but is crucial for sites generated by static site generators. For example, if you're using Next.js, your `next build` command might look like this: ```bash npm run build ``` Or, if you're using a `package.json` script: ```json "scripts": { "build": "next build" } ``` Another important configuration is setting up environment variables. For a static site hosted on myproject.is-pro.dev, you might set an environment variable `BASE_URL` to `https://myproject.is-pro.dev` to ensure that all absolute URLs in your site point to the correct location. | Configuration Option | Description | Example Value | | --- | --- | --- | | Build Command | Command to build your static site | `npm run build` | | Base URL | Base URL for your static site | `https://myproject.is-pro.dev` | | Custom Domain | Custom domain or subdomain for your site | `myproject.is-pro.dev` | ## Common pitfalls and solutions Several common pitfalls can occur during the deployment process: 1. **Incorrect Git Repository Linking**: If your local repository is not correctly linked to the is-cool-me repository, your changes won't deploy. Solution: Verify the repository URL and retry the `git remote add` command. 2. **DNS Configuration Errors**: Incorrect DNS settings can prevent your custom subdomain from resolving. Solution: Check the DNS records and ensure they point to is-cool-me's servers. 3. **Build Command Errors**: If the build command fails, your site won't deploy. Solution: Check the build logs for errors and fix the issue, possibly by updating dependencies or fixing code errors. 4. **Environment Variable Misconfiguration**: Incorrect environment variables can lead to broken links or functionality. Solution: Review your environment variables and ensure they match your site's requirements. 5. **File Permissions Issues**: Incorrect file permissions can prevent is-cool-me from reading your website files. Solution: Adjust the file permissions to allow read access. ## Best practices To ensure your static website performs well, is secure, and is easy to maintain, follow these best practices: - **Optimize Images**: Compress images to reduce file size and improve page load times. - **Use a CDN**: If possible, use a Content Delivery Network (CDN) to serve static assets, reducing latency. - **Keep Dependencies Updated**: Regularly update your dependencies to ensure you have the latest security patches and features. - **Monitor Performance**: Use tools like WebPageTest or Lighthouse to monitor your website's performance and identify areas for improvement. - **Implement Security Headers**: Set appropriate security headers to protect your site from common web vulnerabilities. ## Troubleshooting section When troubleshooting deployment issues, start by checking the deployment logs for errors. If you're using a static site generator, ensure that the build process completes successfully. For DNS-related issues, use tools like `dig` or online DNS checker tools to verify that your DNS records are correctly configured. Here's an example of how to use `dig` to check the A records for your custom subdomain: ```bash dig +short myproject.is-pro.dev ``` This command should return the IP address of the is-cool-me server hosting your site. If it doesn't, there might be a DNS configuration issue. ## Deployment scenario from operations Let's consider a real-world example where we're deploying a static blog generated by Jekyll to the custom subdomain blog.myproject.is-pro.dev. The first step is to create a new repository on is-cool-me for our blog and initialize a Git repository in our local project directory. We then add our blog files to the repository, commit them, and push the changes to is-cool-me. Next, we configure the custom subdomain on the is-cool-me dashboard, specifying that our repository contains a Jekyll site. We set the build command to `jekyll build` and specify the output directory as `_site`. Finally, we set the base URL environment variable to `https://blog.myproject.is-pro.dev` to ensure all links in our blog are absolute and point to the correct location. ## Common mistakes Here are some common mistakes to avoid: * Not initializing a Git repository in the local project directory * Forgetting to add and commit all website files * Incorrectly specifying the build command or output directory for static site generators * Failing to configure the custom subdomain on the is-cool-me dashboard * Not setting the base URL environment variable correctly ## How to verify it works To verify that your static website has been successfully deployed to your custom subdomain, follow these steps: 1. **Check the Website**: Navigate to your custom subdomain (e.g., myproject.is-pro.dev) in a web browser to ensure your website is visible and functions as expected. 2. **Verify DNS Resolution**: Use tools like `dig` or `nslookup` to verify that your custom subdomain resolves to the correct IP address. 3. **Test Links and Assets**: Click through your website to ensure all links work correctly and that assets like images and CSS files are loading properly. 4. **Check for Security Headers**: Use the browser's developer tools or online security header checkers to verify that appropriate security headers are set. 5. **Monitor Performance**: Use performance monitoring tools to ensure your website loads quickly and efficiently. ## Conclusion with next steps Deploying a static website to free hosting with a custom subdomain is a straightforward process that can be completed with the right tools and knowledge. By following the steps outlined in this guide, you can have your static website up and running on a custom subdomain like myproject.is-pro.dev in no time. Next steps include monitoring your website's performance, ensuring security best practices are followed, and exploring additional features offered by is-cool-me to further enhance your website. ## FAQ ### Q: What is the difference between a custom domain and a custom subdomain? A: A custom domain refers to a fully custom domain name (e.g., myproject.com), while a custom subdomain refers to a subdomain of a larger domain (e.g., myproject.is-pro.dev). Custom subdomains are often provided for free by hosting platforms, while custom domains usually require purchasing the domain name. ### Q: How do I handle email for my custom subdomain? A: Handling email for a custom subdomain typically involves setting up mail servers or using a third-party email service. However, this is usually not necessary for static websites, as they do not typically handle email. ### Q: Can I use a static site generator with free hosting and a custom subdomain? A: Yes, many free hosting platforms support the use of static site generators like Jekyll, Hugo, and Next.js. You simply need to configure the build command and output directory correctly in your repository settings. ### Q: What are the limitations of free hosting with a custom subdomain? A: Limitations can include bandwidth and storage limits, restrictions on the types of files that can be hosted, and potential ads displayed on your website. Always review the terms of service for your hosting platform to understand any limitations. ### Q: How do I migrate my website from one hosting platform to another? A: Migrating a website involves transferring your website files, configuring DNS settings, and updating any environment variables or build commands as necessary. It's essential to follow the specific migration guides provided by your hosting platforms to ensure a smooth transition.
Share this article Share on X Share on LinkedIn
Previous A Step-by-Step Guide to Setting Up a Secure Subdomain for E-commerce Websites