Apache 2.2 Websocket Proxying on Ubuntu with mod_proxy_wstunnel

Until recently, I was running a Node.js web application using Websockets with socket.io alongside an Apache web server. I wanted Apache to run on port 80 and serve both sites using name-based virtual hosting. However, Apache httpd mod_proxy couldn’t proxy Websockets correctly.

I discovered that there is a new mod_proxy_wstunnel module in the Apache httpd source trunk in an article describing how to backport mod_proxy_wstunnel to Apache 2.4 or 2.2. I figured out the specific steps for doing this on Ubuntu (tested on 11.10 with Apache httpd 2.2.20). I wanted to add them as a comment, but they were disabled on that blog.

Here are the steps, see the original blog post of the patch author for more information:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Check apache version (should be 2.2.20 as of writing, if not adjust the next step)
dpkg -s apache2
 
# Checkout apache source
svn checkout http://svn.apache.org/repos/asf/httpd/httpd/tags/2.2.20/ httpd-2.2.20
 
# Get patch and apply it
wget http://cafarelli.fr/gentoo/apache-2.2.24-wstunnel.patch
cd httpd-2.2.20
patch -p1 < ../apache-2.2.24-wstunnel.patch
 
# Build Apache 
svn co http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x srclib/apr
svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x srclib/apr-util
./buildconf # EDIT: Some commenters noted that buildconf should be run before the configure
./configure --enable-proxy=shared --enable-proxy_wstunnel=shared
make
 
# Copy the module and recompiled mod_proxy (for new symbols) to the ubuntu apache installation and update the permissions to match the other modules
sudo cp modules/proxy/.libs/mod_proxy{_wstunnel,}.so /usr/lib/apache2/modules/
sudo chmod 644 /usr/lib/apache2/modules/mod_proxy{_wstunnel,}.so
echo -e "# Depends: proxy\nLoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so" | sudo tee -a /etc/apache2/mods-available/proxy_wstunnel.load
 
# Enable the module (also make any configuration changes you need)
sudo a2enmod proxy_wstunnel
sudo service apache2 restart

Ubuntu: Running a command in GNU screen on boot as another user

Add to /etc/rc.local before the ‘exit 0’ line:

mkdir /var/run/screen
chmod 775 /var/run/screen
chgrp utmp /var/run/screen
su USER -c 'screen -m -d -S SCREENNAME bash -c "COMMAND"'

Replace USER with the user you want the command to run as. SCREENNAME with any name you like, and COMMAND with the actual command to run in the screen.

The first three lines were necessary to work around a bug in screen on Ubuntu.

Getting URLs to line break in LyX

LyX is generally pretty good, but sometimes things that should be simple can be a pain. I couldn’t successfully get long URLs to wrap over multiple lines rather than overflowing off the edge of the page until I read this obscure bug report after about 5 minutes of Googling.

What worked for me was using Insert->URL instead of Insert->Hyperlink. Simple as that, I didn’t even notice there were two different options previously.

As a bonus you can make URLs clickable in PDFs by going to Document->Settings->PDF Properties->Use Hyperref Support.

Organise digital voice recordings

Recording lectures with a USB digital voice recorder left me with a lot of obscurely named files. Naming them according to what the lecture subject was by hand would have been very time consuming. I wrote a script to take an ical calendar file and match up recordings from the device with events on the calendar.

Given an input and output directory and a path to an ical calendar file (may be at a remote URL to use with Google Calendar or similar) the script will copy files and rename them according to corresponding events. Where there are multiple (or no) events occuring around the time of the recording, the script will name the recording as ‘uncategorised’.

It needs the icalendar module to run. The script can be downloaded here. See also the GitHub page.

It’s not limited to organising voice recordings and could be used to label any files with calendar events based on their modification timestamp.

Clarify Amazon Used and New Prices by including Postage and Packaging

Here is a small script I’ve written which seeks to improve Amazon product pages by including postage and packaging in ‘used and new’ prices. The prices including delivery are automatically updated whenever you visit a product page.

Updated: Now also gives the option to show prices including delivery in search results.

Examples

Once you click through to the ‘used and new’ page itself, prices including P&P are shown too.

Install instructions for Firefox

  1. Install the Greasemonkey addon
  2. Restart Firefox if necessary
  3. Go to the Userscripts.org page and click ‘Install’ at the top right of the page

Install instructions for Chrome

  1. Install the Tampermonkey addon
  2. Go to the Userscripts.org page and click ‘Install’ at the top right of the page
  3. Click ‘OK’ twice in the dialogs that appear

Notes

It’s very untested, having not existed for long.

The script is currently not functional for Amazon.jp or Amazon.cn.

Neither I or the script are in any way affiliated with Amazon.com, Inc. All trademarks and copyrights are property of their respective owners.

Github repository (report bugs here)

JavaScript – Reload window without query string

Here is a way to reload/refresh the current web page in JavaScript, removing any query string parameters in the process:

1
window.location = window.location.pathname;

This preserves protocol selection (HTTP/HTTPS) and is more succinct than the existing methods I found on Google. Note that this will remove the fragment as well (#part).

More information about the location object

Italy and the End, for now…

We’d stayed in Budapest much longer than originally intended, for the simple reason that it was brilliant! However, we had to make our way to our final destination in North Italy – Sëlva di Val Gardena. The train journey was long and there was a bus to get at the end of it, so we decided to split our journey halfway in Salzburg. Unfortunately the hostel there turned out to be consummately awful, my favourite thing about it was writing a scathing review for Hostelbookers. I don’t think there is a way to directly link, but it’s somewhere among the others, some of which are bafflingly positive. We didn’t really do anything in Salzburg except traipse from the station to the hostel and back, so I can’t really say anything except that it’s rather expensive.

Once that leg of the journey was over, after several windy buses along sheer cliff faces, we arrived in Sëlva. We had a great time there, fitting in a lot of mountain trekking along with the usual gastronomic odysseys that you will be bored of reading about if you’ve seen my earlier articles. There were a lot of peaceful hillsides with very relaxed-looking and bell-wearing cows tinkling along. The views are spectacular and the air clean and refreshing. It was an invigorating and relaxing place to finish our trip.

A precariously parked Land Rover

They get a lot more interested when you open your backpack

Interrailing with Lucy was a great experience and I really want to do it again as soon as possible. It was refreshing to get out of the UK for an extended period. I liked not being aware of anything going on at home, though I am a bit addicted to online news and must admit I did peek. The almost constant sunshine helped a lot too. It was interesting seeing the little differences between every country, and feeling more European than British for probably the first time. It was embarrassing being so incompetent when it comes to languages, I should try to learn some more before going next time. I do not think I will ever be conversant in Hungarian or Slovak though.

A typically rainy Gatwick airport greeted us after a reasonably short flight from Innsbruck (a fantastically small airport with no multi-mile walks to get in and out). That was unfortunately the end of our Interrailing, for now…