Monday, May 31, 2010

Serving static file in nginx with a some check

Recently I developed  a small web site for my lab, and we are hosting it on Google App Engine (GAE), as Google provides quite enough resources for a site of several pages ;)

However we also need to provide download of huge files, which can not be store in GAE, thus we had to host it in one of our severs. Initially we do not want our content directly accessible, so we want to use dynamic URL but we don’t want to loose the performance of nginx.

My final solution is use rsa module by Sybren A. Stuvel (which is pure python) to encrypt the real url (with fixed private key) in GAE, and give the encrypted url to user. In the file host, I use nginx’s X-Accel-Redirect feature and a tiny cherrypy server to decrypt the url (with corresponding pub key), and simply set the X-Accel-Redirect header to the real internal path of nginx.

This solution works well in my case :)

Wednesday, May 12, 2010

Mount qemu harddisk image in host system

Recently I got to copy a lot of files from a qemu guest, and I think using network is too slow, so I googled for solutions to mount qemu image in host system (when guest is shutdown). And it turns out that only raw images are supported, therefore the first step is to convert the image format:

qemu-img convert –f qcow2 origin.qcow –O raw temp.raw

Then I fount in archlinux wiki that I should mount with –loop,offset=32256 option, but I fail to figure out where 32256 comes. Luckily I remenbered how I delt with dd images. Just get the offset with fdisk:

fdisk –u –l temp.raw


Then I have the sector size (512 in my case) and the offset (2048, start sector of my partation), so the offset should be 512*2048=1048576. (btw, you can calculate with bc: echo ‘512*2048’ | bc)



mount –t ext4 –o loop,offset=1048576 temp.raw /mnt/some-path


That’s it :)