Search code examples
ruby-on-rails-4herokugithubdropboxstatic-pages

Hosting static website on Dropbox,Github,Heroku,Amazon S3 - Compare


I'm a rails developer. I'm looking to host my static website without paying monthly subscription.I'm expecting users between 50,000 - 100,000. Heroku provides 512mb free dyno and Amazon S3 gives 20000 get request for free.

Do you think hosting static pages on Github and Dropbox have better result and more get request then Amazon and Heroku?


Solution

  • Using GitHub Pages To Host Your Website

    Create Your GitHub Repository

    The files that make up your website will need to be stored within a GitHub repository. If you’re creating a website to promote one of your existing GitHub projects you can add the website files to a new branch, otherwise you can just setup a new repo for your site.

    Note: If you are not adding your website files to an existing repo make sure that you setup a new repo before continuing.

    Now open up terminal (command prompt on Windows) and make sure that you have a copy of your GitHub repo on your computer. Once you got your local copy, move into the project folder using the cd command.

    // Retrieve a copy of your GitHub repo.  
    git clone https://github.com/user/repository.git
    // Move into that directory.
    cd repository
    

    Note: Make sure that you change the clone URL to the URL of your GitHub repo. This can be found on the main project page.

    Creating an Orphan Branch

    Now you need to create a new orphan branch within your repo that will hold all of your website files.

    This new branch should be called gh-pages.

    git checkout --orphan gh-pages
    

    If you already had files in the master branch of your GitHub repo you now need to delete these from the new gh-pages branch. To do this you can use the following command:

    git rm -rf .
    

    Adding Your Website Files

    Now that your repo has been properly setup it’s time to add all of the HTML, CSS and JavaScript files that make up your website. Once you have added these to your repo you need to commit the changes. To do this you can use the following command.

    git commit -a -m "Adding pages"
    

    Note: The -a flag is shorthand for git add .

    Pushing Your Changes to GitHub

    Okay so you’ve got all your files where they need to be. The only thing left to do now is to push the new gh-pages branch up to GitHub. You do this using the git push command.

    git push origin gh-pages
    

    That’s it! Your website should now be available at http://username.github.io/repository/.

    Using a Custom Domain

    The last thing I want to cover in this post is how you can use your own domain name with your new GitHub-hosted website.

    First you will need to create a new file in your GitHub repo called CNAME that contains the domain name (or subdomain) that you wish to use. This file should be placed in the gh-pages branch if you are using project-pages (as we have been in this post). If you are using user-pages the file should be placed in the master branch.

    Your CNAME file might look like the following:

    xcode42.com
    

    Next you will need to update the DNS records for your domain name. This is usually done through a control panel provided by your domain registrar.

    If you want to use a root domain (such as http://www.xcode42.com) for your website you will need to setup a new A record that points to the IP address 204.232.175.78.

    If you are using a subdomain (such as abc. xcode42.com) it’s best to create a new CNAME record that points to your GitHub user subdomain (username.github.io). This is so that the DNS will be automatically adjusted if the servers IP address changes on GitHub.

    It may take a little while for your DNS changes to take effect. This is usually no more than a few hours. Once the changes have gone through, you should be able to access your new website from your custom domain name.

    --

    GitHub pages does limit you to using static assets (HTML, CSS and JS) for your websites, but you could use something like Jekyll to make it easier to generate these files.

    It’s not going to meet everyone’s needs but if you just want to launch a simple website, GitHub pages is a quick and easy way to get started.