Hosting from my Home PC, and Still Able to Handle a lot of Traffic

Written by
Date: 2012-02-28 16:47:00 00:00


I'm always trying to cut costs, and still have a good service (I'm sure I'm not the only one). These days I've trying to optimize my blog, so it can be faster for my readers but without increasing the cost on my site.

What I'm doing is hosting from my home PC, you may say "Are you nuts?", specially if you consider that I live in Bolivia, but yes that is what I'm doing.

Here is how:

First I blog using Jekyll, so all my blog is static content, no drupal, wordpress or the like, so not LAMP needed just a small computer with Linux and Nginx, a public IP, an UPS and that's it. I'm ready.

But what about the latency? What about the bandwidth?

I'm solving those issues with cloudfront configured with custom origin.

For those of you who do not know about cloudfront, it is a service from Amazon, actually it is a CDN service from Amazon.

I did not know this, but Cloudfront can now serve from an S3 bucket but also from your own server, this way you can use it as a cache in the cloud. I mean is like having varnish servers all over the world, so the latency is low, and the bandwidth and work needed from your server is really low.

If you setup the "expires" header correctly, you can have offer really a good experience to your users. What I've done is to set a expires header of 1h for index.html page, and 48h for the rest of elements in the blog, as usually only index.html page changes when a new post is inserted and the rest remain the same.

I'm using NGINX in the back end, so I've something like this in nginx.conf file.

server {
    listen [::]:80;
    gzip on;
    server_name     my.domain.com;
    expires +48h;
    access_log      /var/log/nginx/access.log;
    location / {
    index index.html;
    charset   utf-8;
    proxy_set_header  Accept-Encoding  "";
    root  /srv/http/nginx;
    
}

    location /index.html {
            expires +1h;
            proxy_set_header Accept-Encoging "";
    }
}

If you have "clean urls" in your PHP CMS, with no query in the url, you can also use Cloudfront to cache your blog. I have not tested it with dynamic content, but if your dynamic content is not so dynamic, it may worth a try, I mean blogs are not really dynamic. Any wordpress, Drupal or Joomla blog, should be eligible to work in this configuration.