Skip to main content

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

Follow this step-by-step guide to deploy a static website to free hosting with a custom subdomain, covering DNS setup and website configuration.

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, as it allows them to showcase their projects and applications without incurring significant costs. Static websites are ideal for projects that do not require server-side rendering or dynamic content generation, such as personal portfolios, blogs, and documentation sites. With the rise of free hosting platforms like is-cool-me, developers can now easily deploy their static websites to custom subdomains like myproject.is-pro.dev. This tutorial will guide developers through the process of deploying a static website to free hosting with a custom subdomain, covering the necessary prerequisites, step-by-step instructions, and common pitfalls to avoid. The motivation behind this topic is to provide developers with a comprehensive guide on how to leverage free hosting platforms to deploy their static websites. By following this tutorial, developers can save time and resources, and focus on building and improving their projects. Additionally, this tutorial will cover the importance of DNS setup, custom subdomain configuration, and security considerations to ensure a smooth and secure deployment process. ## Prerequisites Before starting the deployment process, developers need to have a few prerequisites in place. Firstly, they need to have a static website ready for deployment, which can be built using popular frameworks like React, Angular, or Vue.js. Secondly, they need to have an account on is-cool-me, which provides free hosting for static websites. Thirdly, they need to have a custom subdomain configured, such as myproject.is-pro.dev. Lastly, they need to have a basic understanding of DNS setup and configuration. To get started, developers can create a new repository on GitHub or GitLab, and initialize a new static website project using a framework of their choice. For example, they can use the create-react-app command to create a new React project: ```bash npx create-react-app myproject ``` They can then configure their project to use a custom subdomain, such as myproject.is-pro.dev, by updating the package.json file: ```json { "name": "myproject", "version": "1.0.0", "homepage": "https://myproject.is-pro.dev", ... } ``` ## Step-by-step instructions To deploy a static website to free hosting with a custom subdomain, follow these step-by-step instructions: 1. Create a new repository on GitHub or GitLab, and initialize a new static website project using a framework of your choice. 2. Configure your project to use a custom subdomain, such as myproject.is-pro.dev, by updating the package.json file. 3. Create a new file called CNAME in the root of your project, and add the following line: ``` myproject.is-pro.dev ``` 4. Commit and push your changes to the remote repository. 5. Log in to your is-cool-me account, and navigate to the dashboard. 6. Click on the "New Project" button, and select "Static Website" as the project type. 7. Enter the repository URL, and select the branch to deploy. 8. Configure the DNS settings by adding a new record with the following values: | Type | Name | Value | | --- | --- | --- | | CNAME | myproject | myproject.is-pro.dev | 9. Save the changes, and wait for the deployment to complete. 10. Verify that your website is live by visiting the custom subdomain URL, such as https://myproject.is-pro.dev. ## Configuration deep-dive The configuration options for deploying a static website to free hosting with a custom subdomain are extensive. Here are some examples of real values: * Custom subdomain: myproject.is-pro.dev * Repository URL: https://github.com/username/myproject.git * Branch: main * DNS settings: | Type | Name | Value | | --- | --- | --- | | CNAME | myproject | myproject.is-pro.dev | | A | @ | 192.0.2.1 | * Environment variables: | Name | Value | | --- | --- | | NODE_ENV | production | | API_URL | https://api.myproject.is-pro.dev | For example, to configure the API URL environment variable, you can add the following line to your .env file: ```makefile API_URL=https://api.myproject.is-pro.dev ``` You can then use this variable in your code to make API requests: ```javascript fetch(`${process.env.API_URL}/endpoint`) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); ``` ## Common pitfalls and solutions Here are some common pitfalls to avoid when deploying a static website to free hosting with a custom subdomain: 1. **Incorrect DNS settings**: Make sure to configure the DNS settings correctly, including the CNAME and A records. Solution: Double-check the DNS settings, and verify that the records are propagated correctly. 2. **Invalid repository URL**: Ensure that the repository URL is correct, and the branch is set to the correct one. Solution: Verify the repository URL, and update the branch settings if necessary. 3. **Custom subdomain not configured**: Make sure to configure the custom subdomain correctly, including the CNAME record. Solution: Update the CNAME record, and verify that the custom subdomain is configured correctly. 4. **Environment variables not set**: Ensure that the environment variables are set correctly, including the API URL and NODE_ENV. Solution: Update the environment variables, and verify that they are set correctly. 5. **Deployment not completing**: Verify that the deployment is completing successfully, and the website is live. Solution: Check the deployment logs, and troubleshoot any issues that may be causing the deployment to fail. ## Best practices To ensure a smooth and secure deployment process, follow these best practices: * Use a version control system like Git to manage your codebase. * Configure environment variables to keep sensitive data secure. * Use a secure protocol like HTTPS to encrypt data in transit. * Monitor your website's performance and security using tools like Google Analytics and WebPageTest. * Keep your dependencies up-to-date, and ensure that your code is compatible with the latest versions. For example, to configure HTTPS for your custom subdomain, you can use the following command: ```bash openssl req -x509 -newkey rsa:2048 -nodes -keyout myproject.is-pro.dev.key -out myproject.is-pro.dev.crt -days 365 -subj "/C=US/ST=State/L=Locality/O=Organization/CN=myproject.is-pro.dev" ``` ## Troubleshooting section To troubleshoot issues with your deployment, follow these diagnostic steps: 1. Check the deployment logs for any errors or warnings. 2. Verify that the DNS settings are configured correctly. 3. Ensure that the custom subdomain is configured correctly. 4. Check the environment variables, and verify that they are set correctly. 5. Test the website using a tool like curl or Postman to verify that it is working as expected. For example, to test the API endpoint using curl, you can use the following command: ```bash curl -X GET https://api.myproject.is-pro.dev/endpoint ``` ## Deployment scenario from operations Here is a complete real-world example of deploying a static website to free hosting with a custom subdomain: * Custom subdomain: myproject.is-pro.dev * Repository URL: https://github.com/username/myproject.git * Branch: main * DNS settings: | Type | Name | Value | | --- | --- | --- | | CNAME | myproject | myproject.is-pro.dev | | A | @ | 192.0.2.1 | * Environment variables: | Name | Value | | --- | --- | | NODE_ENV | production | | API_URL | https://api.myproject.is-pro.dev | To deploy the website, follow these steps: 1. Create a new repository on GitHub, and initialize a new static website project using a framework of your choice. 2. Configure the project to use a custom subdomain, such as myproject.is-pro.dev, by updating the package.json file. 3. Create a new file called CNAME in the root of the project, and add the following line: ``` myproject.is-pro.dev ``` 4. Commit and push the changes to the remote repository. 5. Log in to your is-cool-me account, and navigate to the dashboard. 6. Click on the "New Project" button, and select "Static Website" as the project type. 7. Enter the repository URL, and select the branch to deploy. 8. Configure the DNS settings by adding a new record with the following values: | Type | Name | Value | | --- | --- | --- | | CNAME | myproject | myproject.is-pro.dev | 9. Save the changes, and wait for the deployment to complete. 10. Verify that the website is live by visiting the custom subdomain URL, such as https://myproject.is-pro.dev. ## Common mistakes Here are some common mistakes to avoid when deploying a static website to free hosting with a custom subdomain: * Not configuring the custom subdomain correctly * Not setting the environment variables correctly * Not configuring the DNS settings correctly * Not testing the website thoroughly before deployment * Not monitoring the website's performance and security after deployment For example, to avoid not configuring the custom subdomain correctly, make sure to update the CNAME record with the correct value: ``` myproject.is-pro.dev ``` ## How to verify it works To verify that your deployment is working correctly, follow these steps: 1. Visit the custom subdomain URL, such as https://myproject.is-pro.dev, to verify that the website is live. 2. Test the API endpoint using a tool like curl or Postman to verify that it is working as expected. 3. Verify that the environment variables are set correctly, and the website is using the correct values. 4. Monitor the website's performance and security using tools like Google Analytics and WebPageTest. 5. Test the website's functionality, including any forms or interactive elements, to verify that they are working correctly. For example, to test the API endpoint using curl, you can use the following command: ```bash curl -X GET https://api.myproject.is-pro.dev/endpoint ``` ## Conclusion with next steps In conclusion, deploying a static website to free hosting with a custom subdomain is a straightforward process that requires careful configuration and testing. By following the steps outlined in this tutorial, developers can ensure a smooth and secure deployment process. Next steps include monitoring the website's performance and security, and making any necessary updates or changes to the codebase. To get started, developers can create a new repository on GitHub or GitLab, and initialize a new static website project using a framework of their choice. They can then configure the project to use a custom subdomain, such as myproject.is-pro.dev, and deploy it to free hosting using is-cool-me. ## FAQ Here are some frequently asked questions about deploying a static website to free hosting with a custom subdomain: Q: What is the difference between a CNAME record and an A record? A: A CNAME record maps a custom subdomain to a canonical domain name, while an A record maps a custom subdomain to an IP address. For example, a CNAME record might map myproject.is-pro.dev to myproject.github.io, while an A record might map myproject.is-pro.dev to 192.0.2.1. Q: How do I configure environment variables for my static website? A: Environment variables can be configured using a .env file or a similar mechanism, depending on the framework or platform being used. For example, to configure the API URL environment variable, you can add the following line to your .env file: ```makefile API_URL=https://api.myproject.is-pro.dev ``` Q: What is the best way to monitor the performance and security of my static website? A: The best way to monitor the performance and security of your static website is to use tools like Google Analytics and WebPageTest. These tools can provide insights into page load times, user engagement, and security vulnerabilities, and can help you identify areas for improvement. Q: How do I troubleshoot issues with my deployment? A: To troubleshoot issues with your deployment, follow the diagnostic steps outlined in the troubleshooting section of this tutorial. This includes checking the deployment logs, verifying the DNS settings, and testing the website using tools like curl or Postman. Q: What are some common pitfalls to avoid when deploying a static website to free hosting with a custom subdomain? A: Some common pitfalls to avoid include not configuring the custom subdomain correctly, not setting the environment variables correctly, and not configuring the DNS settings correctly. Additionally, it's essential to test the website thoroughly before deployment, and to monitor the website's performance and security after deployment.
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