How-to: Bazaar smart server on Nginx

This is a recipe which will teach you how to set-up a Bazaar smart server on top of the great Nginx HTTP server. I will not deal with optimization or fancy setups at all, the goal is just having your Bazaar branches published, feel free to comment if you feel like the proposed setup could be improved.

First of all, you will need the following:

  • An Un*x box. It does not matter which particular incarnation you prefer (*BSD, GNU/Linux, MacOS X…), just make sure the following components work with your operating system of choice.
  • Bazaar 1.0 or newer.
  • Nginx 0.6.x with the latest mod_wsgi builtin (Manlio did a great job bringing WSGI support o life!)
  • Your text editor of choice.

Now, the recipe for a read-only repository of Bazaar branches:

  1. Install Nginx with mod_wsgi. If you are a fortunate Gentoo user, you can use the Nginx ebuilds from my overlay the Connectical Overlay, just make sure you set python USE-flag when emerging www-servers/nginx.
  2. Create a directory where you will store your branches. I myself decided to place them under /home/bzr. Make sure that Nginx will be able of reading its contentse e.g. by making the directory and its contents world-readable.
  3. Write a small Python script which creates a WSGI application for the smart server and save it to /home/bzr/smartserver.wsgi. It should look like the following:
          from bzrlib.transport.http import wsgi
    
          application = wsgi.make_app(
             root="/home/bzr",
             prefix="/bzr",
             path_var="REQUEST_URI",
             readonly=True)
  4. Edit /etc/nginx/nginx.conf and add the directives into a server section, be sure to use the same location as in the prefix variable above:
          location /bzr {
             wsgi_pass /home/bzr/smartserver.wsgi;
          }
  5. Restart Nginx and enjoy: Now you can access a branch stored at /home/bzr/mybranch using the bzr+http://host/bzr/mybranch URL.

Final note: you must have include wsgi_vars somewhere in your Nginx configuration file, in a server section. That’s all for today. And remember… Bazaar and Nginx are a joy to work with! 😉

Advertisements

4 thoughts on “How-to: Bazaar smart server on Nginx

  1. Pingback: links for 2008-03-11 « Bloggitation

  2. Onde te meteches onte Adri? Que te andiven buscando para darche algo que estiven de cumple! =)
    A ver se nos vemos un día destes pola facultade…jaja.
    Un bico! :*

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s