Link: Nginx Hacking Tips

This is a good overview of common configurations comparing nginx's syntax to apache's.  Once you get used to it, I think nginx syntax is easier to understand, and it reads more like an actual script or program.  I've been using nginx to host for 3 months now and its been very solid.  In fact, it coupled with moving mysql to its own slice, forced me to focus some attention on SQL query bottlenecks.

Nginx has a major limitation in rewrite rules in that you cannot impose multiple conditions for a rewrite rule. Apache HTTPD on the other hand provides a good solution using multiple RewriteCond directives. Nginx on the other hand allows if statement. You can have rewrite rules within if blocks. However the if block themselves are limited. You do not have and or or to add multiple conditions to a single if block. Also you cannot nest if blocks. There are no else statement either. However you can use regular expressions so the following is possible:

Nginx Hacking Tips


My Desktop is a little “Freer”

But really, what does that get me?

It was with a bit of a smirk that I read about Ubuntu user’s pains in upgrading to Karmic, the latest release. Ubuntu’s previous release upgrade or two had killed my networking, to the point that I had to reinstall the whole OS and I instead switched to Arch Linux. Arch has a rollng release cycle, which means you can get the latest and greatest much quicker than a lot of other Linux distributions, and it tries to “Keep it Simple”

This doesn’t mean its easy to install or configure, just that its straightforward to install and configure pieces to really tailor it to your own preferences.

This also does not mean you are not immune to upgrade headaches, as I found out this weekend. The latest version of X-Server 1.7, does not play well with the latest binary NVidia video card drivers. To the point that X will not load and you’re left at an old school command line terminal. The solution is to switch to the Open Source nouveau drivers for nvidia cards, which don’t have the same incompatibility. I had to also edit my xorg.conf file to get my dual-monitor setup working correctly, which was easy once google found me a working configuration to crib.

An hour later, I have a usable Linux machine again, but honestly, weren’t we supposed to be past this by now? Whatever KDE+Xorg configuration I have does not have the right juju to configure this via KDE’s gui apps for my desktop or screen resolution. According to KDE I do not appear to have a multi monitor setup, but other tools do show the two monitors available. Its just that they don’t all talk to each other as expected or needed in all cases. Too many things have to align for configuration/hardware stuff like this to be painless, so Linux will continue to be challenging to run.


Using RewriteMap for many URL redirects.

Migrating platforms can lead to broken links on your website.  If you’ve cultivated links from other sites or if search engines send a lot of visitors your way, you’ll want to redirect users from the old links to the new.  Many content management systems have facilities for manually maintaining redirects, but you can also do this with Apache.  The big benefit of using Apache is that such visitors won’t hit your CMS until they get to the correct page.

One way to redirect users is through mod_rewrite and clever use of its Rewrite Rules. If you have a lot links to redirect, you don’t want to create one rule for each link, since its essentially the same pattern for each link.  This is where the rewrite modules RewriteMap directive comes in handy.

In your VirtualHost or Server sections, add something like the following, making sure to change the rewrite rule regular expression to match your own situation.

RewriteEngine On
RewriteMap redirect_map txt:/path/to/mysite/redirect_map.txt
RewriteRule ^/news/detail/(.*) ${redirect_map:$1} [R=permanent,L]

Then, in the redirect_map.txt file, you can put the old link and new link one per line and separated by one or more spaces or tabs.

1877-avoiding_frustration_with_php_sessions     /avoiding-frustration-with-php-sessions
1877-avoiding_frustration_with_php_session      /avoiding-frustration-with-php-sessions
2062-howto_use_virtualbox_to_setup_an_internet_explorer_testing_machine /howto-use-virtualbox-to-setup-an-internet-explorer-testing-machine
2067-peter_wilts_pillars_of_management          /peter-wilts-pillars-of-management


Pidgin release adds voice and video chat.

On Windows and Linux, Pidgin is my IM client of choice. On Mac I use Adium, which is sort of related to it since they share some common libraries under the hood, even though there is a Pidgin client for OS X. I’m optimistic that the latest release might make it easier to use voice and/or video chat online. I don’t do that often enough because its usually a headache, even with iChat. iChat used to work fine but with Verizon’s FIOS router, I have to put my computer in the DMZ outside the router’s firewall to get it to work. Look for it to make it into your linux distro soon, I suspect ArchLinux will have it pretty quick. Voice and Video chat is not yet in Windows.

Pidgin 2.6.1 Adds Voice and Video Support

Pidgin, got a major update last week that includes support for voice and video. Pidgin 2.6.1 also includes more than 200 bugfixes and patches, plus a few additional new features that may not be as sexy as voice and video but are still great to have.


Useful SVN one-liner

Add it to your aliases, this one liner adds all unrecognized files in the current directory (preceded by ? in svn status) to a svn project.

svn st | grep '^?' | cut -d ' ' -f 7 | xargs svn add

Thank you, dd for saving and restoring my MBR

I finally got around to upgrading my dual-boot desktop PC to running Windows XP.  It was just about time, the version of windows I was running was no longer supported and more and more software requires Windows XP nowadays.  I also wanted to start using my Windows partition for more than World of Warcraft and occasional IE6 Testing.  Mini-rant: One might think that, by now, Windows would play nicely if you are installing it on an existing dual-boot setup and not do rude things like naively overwrite your Master Boot Record.  If one thought that, however, one would be very naive indeed.

The common wisdom, when setting up a dual booth system, is to install Windows first, then your other operating systems, since the latter are smart enough to setup a menu at boot time to choose which OS to load.  That’s find advice for a fresh setup, but if you have an existing system you have to take one precaution that will save you time and headaches.  First, make sure you have some sort of Linux "Live" or Install CD that you can boot from after Windows is setup.  Second, before installing Windows, you’ll want to backup your MBR to some removable media, like a USB disk, so that you can restore it after Windows does its thing.

To backup your MBR, use the dd tool, keep in mind you’ll need to change the input and output files to reflect your own system:

dd if=/dev/sda of=/media/usb1/sda-mbr.bin bs=512 count=1

Likewise to restore it, boot your rescue disk, insert your flash drive and run the following to copy it back to the boot drive

dd if=/media/usb1/sda-mbr.bin of=/dev/sda bs=512 count=1

This worked for me, but it could be a bit more intricate. I followed the advice found here and here.


World of Goo available on Linux

Patty, Staci, and I have played World of Goo on the Wii and were quickly addicted to it. It’s awesome to see that the developers have ported it to Linux, alongside Mac and Windows versions. If you’re looking for a good puzzle game thats easy to play in short chunks of time, I highly recommend World of Good. 2D Boy: I love you, 2D Boy! » Blog Archive » World of Goo Linux Version is Ready!

The Linux version of World of Goo is finally ready for download! It’s available exclusively from our site, in three different packages depending on what your computer likes. (tar.gz, deb, rpm)


Check out for backups

I’ve been using to have nightly offsite back ups for configuration files, database snapshots, and web sites on this server.  They provide a great service that works really well and helps me sleep a little better at night.  If you need a backup service, I’d recommend you give them a serious look, especially after the latest email I received from them.

There are also new developments in pricing and service.  We have lowered our prices by 25% across the board, and as is our practice, we have given all existing customers 30% more space in their accounts.  So without any changes to your billing, you are now receiving our new, lower rate.


Linux video editors might be improving

My last attempt to edit video in Linux, sent me back to iMovie on my Mac and Magix Movie Editor in wondows. It might be time to revisit video editors in Linux.Open Movie Editor: Linux Video Editor with Plot Twists | OStatic

In general, Linux video editors, admittedly, aren’t where Mac video editors are presently. Kino and Jahshaka, two popular “end user” video editing applications for Linux, seem fairly comparable to some of the common “consumer targeted” proprietary applications available for other platforms in terms of features, function, and ease of use.


Troubleshooting connection problems with memcached

I was noticing today many apache segfaults on this server, and pretty high traffic loads at times. I haven’t pinpointed the exact cause of high traffic, there are a couple candidates, but the apache segfaults seem to accompanied by the following PHP errors:

[13-Aug-2008 13:55:27] PHP Notice:  MemcachePool::get() [memcachepool.get]: Server (tcp 11211, udp 0) failed with: Network timeout (0) in /var/vhosts/oam/ on line 579
[13-Aug-2008 13:55:29] PHP Notice:  MemcachePool::get() [memcachepool.get]: Server (tcp 11211, udp 0) failed with: Network timeout (0) in /var/vhosts/oam/ on line 579

This may be related to the local firewall and ip_conntrack, which has a known problem with memcached

> This is because kernel try to track all your memcached connections – ie watch > all tcp/ip connection that you made to your memcache. and because conntrack > table have a limited size , and it must hold a connection information for > relative long time, when this table get overloaded, packets are dropped .

The required iptables rule in that email isn’t quite right, I had to do the following on the server

iptables -t raw -I OUTPUT  -s ip_addrsss of your memcached box --protocol tcp --sport port of your memcached daemon   -j NOTRACK

Here may end my brief fling with memcached. I’d originally installed it after switching to using prepared SQL statements, which do not use mysql’s query cache. I suspect mysql’s query cache is better for local caching, as it may allow mysql to handle client requests much faster. As it is now, mysql is taking more time to do its work, which at some point, knocks memcached offline. For local caches, using the caching mechanism available through php accelerators such as eaccelerator may be a better option to running a local memcached