Building nginx with the push stream module on Debian

I’ve been trying out the push stream module for nginx recently. The instructions for building it are pretty clear, but I also wanted all the benefits of installing it as a package with apt-get.

I found this handy guide which outlines the general procedure. First, make sure that the build dependencies for the package are installed:

sudo apt-get build-dep nginx

Then download the package source:

apt-get source nginx

Add the new module to the source tree:

cd nginx-1.2.1/debian/modules
curl -L | sudo tar zx
mv wandenberg-nginx-push-stream-module-71c511d nginx-push-stream-module

Update the rules file to include the module, and modify the version in the changelog. Then build the package:

dpkg-buildpackage -b

You can now install the required packages:

sudo dpkg -i nginx-common_1.2.1-2.2+wheezy2-push_all.deb nginx-full_1.2.1-2.2+wheezy2-push_amd64.deb nginx_1.2.1-2.2+wheezy2-push_all.deb

Or save them, for use elsewhere. Once the module is installed you need to update the nginx.conf:

    http {
        push_stream_shared_memory_size 256M;

And add a site:

server {
    listen 80;

    location /channels-stats {
        # activate channels statistics mode for this location

        # query string based channel id
        push_stream_channels_path               $arg_id;

    location /pub {
        # activate publisher (admin) mode for this location
        push_stream_publisher admin;

        # query string based channel id
        push_stream_channels_path               $arg_id;

    location ~ /sub/(.*) {
        # activate subscriber (streaming) mode for this location

        # positional channel path
        push_stream_channels_path                   $1;

You can then test the pub/sub functionality using curl:

curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: localhost" -H "Origin: http://localhost" http://localhost/sub/channel1

curl -s 'http://localhost/pub?id=channel1' -d '{"foo": "bar"}'

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s