Cloud Frontin'

Cenote, the server which hosts Aquarionics and 64 other sites of varying complexity, has better things to do than spend its CPU and bandwidth on static content. It’s set up with a memory-limited version of Apache (which I can retune now I’ve bought a larger Linode, but was important at the time) so connections are at a bit of a premium.

The Enterprise solution to this is a CDN, of course, an international network of local stores that make everything better. But CDNs are traditionally tuned for heavy lifting – capital D Downloads rather than asset serving – and aren’t generally useful for one-man-band outfits where most of the readership is in RSS anyway. Plus, it’s something I’d like to do for work, so I was playing with tech.

The solution I’m currently using is Amazon’s Cloudfront, which works in a way pleasingly similar to Epistula (my old CMS)’s Fried Caching system. You point all your static files at a cloudfront-backed domain (in my case with exactly the same URL, and if it’s got it and it’s not too old, it sends it out. If it hasn’t got it, or it’s too old (defined by the caching headers on Aquarionics) it gets it from my server, sends it out, and saves it for later requestors.

This causes a minor problem if I want to change a static file quickly, because the CDN will cache it for ages, but I can either turn off the CDN, or I can invalidate part of the cache using boto like this:

import boto
cf = boto.connect_cloudfront(KEY,SECRET)
cf.create_invalidation_request(CLOUDFRONT_ID, [URI,URI,URI])

It’s currently costing me around $0.05/week, but it’s not very high traffic (Around 6k requests/month), but the site is a hell of a lot faster.

sysadmin windows

Windows 7: How To Automatically Backup Your PuTTY connections

Go to:

  1. Control Panel
  2. Administrative Tools
  3. Task Scheduler
  4. Create Basic Task (In the bar on the right)
  5. Name: “Backup Putty Connections”
  6. Next
  7. Run Daily
  8. Next, Next, Next (Until “Start a Program”)
  9. Program/Script: C:Windowsregedit.exe
  10. Arguments: /E "Putty_connections_backup.reg" "HKEY_CURRENT_USERSoftwareSimonTatham"
  11. Start In: (The directory to put the backups in. Somewhere in your Dropbox would be good)
  12. Open Properties when finished
  13. Finish.
  14. Check the “Run with highest privileges” option (If you don’t see it, find your new task (You may need to click on “Task Scheduler Library”) and right click on it, then select “Properties”)
  15. Right click on it again
  16. Run it.
  17. Make sure the file’s been created.

How to restore them:

  1. Install PuTTY
  2. Double click on that file.

Mass vhosting

My small server currently hosts a number of websites. Too many, really, I should get a bigger server. However, I long ago got bored of creating separate site files for every website I host, so I use MassVHost to make that go away. The same file runs on my dev servers, and it means that to create a new domain all I do is point DNS at it (via hosts, wildcard or whatever) and create a directory with the same name as the site. So, for example, I create /var/www/hosts/ and automatically points there.

This is what that looks like:

(That file is in /etc/apache2/sites-available as “vhosting”, then enabled with a2ensite. This is all under Debian. You’ll also need the vhosting module installed, enabled and working. )

One of the most common things you also need to do is automatically redirect people who go to “www.domain.tld” to “domain.tld” or vice versa depending on your religion. In this world, the canonical name of the site is whatever the directory is called. The thing with the 404 errors and the EverythingIsCatchingOnFire (Spot the reference for five points) stuff means that by default 404s go to this script, which in the event of a “This domain doesn’t exist”, it looks for an appropriate domain and sends you there:

(Meaning not only does go to the right place, but does too)