I’m already sick of my Blaugust project, so I’m writing something else. This is about Amazon Web Services and Nginx config files, mainstream topics everyone can enjoy.

Recent Blog Changes On AWS

823 words.

Recent Blog Changes On AWS

I’m already sick of my Blaugust project, so I’m writing something else. This is about Amazon Web Services and Nginx config files, mainstream topics everyone can enjoy.

I’ve been hosting my blog on AWS (Amazon Web Services) for a while now, and it’s been costing me somewhere between $1 and $2 a month. Somewhat more than the $0/month I was aiming for, but still less than the $5/month of a typical shared Linux hosting plan from the days of yore.

But then I went and looked at my AWS monthly cost during Blaugust and found it had gone way, way up, and that’s when I realized that my 12 months of introductory free AWS services had expired and I had entered the “now you’re paying for reals” phase of usage. So my bill shot up from $2/month to about $30/month. Almost all of that cost is in running an EC2 application server instance which serves up my blog.

The sudden cost spike and the Blaugust activity blitz inspired me to dig into the blog infrastructure again and make some changes, which are now active:

  • First, unrelated to AWS, but I finally figured out how to get Hugo to read the dimensions of linked images and put them into the HTML img tag, so they’re better sized on the pages now, on PC and mobile.
    • For future reference, the key function to know is resources.GetRemote.
  • I finally setup AWS Elastic Beanstalk to redirect http requests to https automatically.
    • “Elastic Beanstalk” is my favorite name for any Internet technology. It’s an AWS platform to deploy and run Internet-connected applications, in this case a tiny Golang http server I wrote as a front-end for the blog.
    • The key place to make the https redirect change is in the Load Balancer configuration, which is somewhat hidden in the interface. You can set it all up with “click ops” if you can find it in the AWS UI, or you can deploy a configuration file in the .ebextensions directory of your Beanstalk application, which is what I did.
  • To try to reduce costs, I downgraded the default Beanstalk settings:
    • I set it to a maximum of one load balancer, instead of the scaling 1-4 it was set at previously.
    • I set the EC2 instance types to t2.nano which I think is the smallest, cheapest possible compute resources Amazon has to run my Golang server. Previously they were set to use either t2.micro or t2.small for some reason.
    • Early indications are that this will cut my AWS bill by a third, bringing it down to around $10/month. Much better, but still not quite the $0/month ideal.
    • I think I can cut usage even more by discarding the load balancers entirely, but setting up a single instance was too much of a hassle for me to deal with (particularly, installing the certificate on EC2 and setting up the TLS).
  • I’ve also started tinkering with the Nginx configuration in Elastic Beanstalk.
    • The entire reason I wrote a tiny Golang server application was to be able to simulate the functionality of an Apache .htaccess file and redirect old links to the new site.
      • Static hosting will serve static pages basically for free but it’s hard (i.e. impossible) to find one that can also redirect all the old links from your fifteen previous blogs so it doesn’t orphan all your readers and all that Google SEO work you’ve done over the years.
      • The only solution I’ve been able to come up with is to add an extra http reverse proxy server between the Internet and the static site that redirects links, hence I wrote a Golang program to do just that.
    • Elastic Beanstalk works by installing Nginx (an HTTP server application, like Apache) on an Amazon EC2 host, and directing traffic to your application with a reverse proxy setup.
    • Elastic Beanstalk also happens to have the capability to customize the Nginx configuration. You can even replace it entirely.
    • Like Apache, Nginx also has the capability to redirect links by giving it a big list in a configuration file. So, I moved my big list of link redirects from my custom Golang application to an Nginx configuration file, offloading that burden from my application and hopefully saving some CPU cycles.
    • Nginx config files are incredibly fussy and complex and prone to syntax errors, so it’s a slow, painstaking process.
    • In the future I want to try setting up the static site reverse proxy directly in Nginx too, which would cut my Golang application completely out of the equation, maybe saving even more CPU cycles.
  • And, while I can leave the static site generation in AWS because that part is basically free, I want to keep my eye out for other, cheaper places to host an Nginx (or Apache, I guess) server. So far I haven’t found anything.

Related

Sorry, new comments are disabled on older posts. This helps reduce spam. Active commenting almost always occurs within a day or two of new posts.