Using Python with Nginx via Passenger

Installing Passenger (Advanced)
This page is for the advanced configuration of Nginx and Passenger, mainly the only differences are:

  • You choose your own source
  • You can add additional configure parameters

If you had a previous Nginx installation, your settings will be preserved. Also you may wish to publish your existing configuration string by typeing nginx -V at the prompt. This will show you the additional parameters that were used when originally building Nginx, remember this for the Passenger installation.

If you have not previously installed Nginx, download and unpack your desired version into the ~/src folder.

cd ~/src
wget http://sysoev.ru/nginx/nginx-0.8.14.tar.gz
tar zxvf nginx-0.8.14.tar.gz

Nginx Advanced Install 1

Unlike the previous page, we’re going to choose the second option.

Nginx Advanced Install 2

The first prompt you’ll receive is asking where your source files are located, in this tutorial I unpacked 0.8.14 to the ~/src/nginx-0.8.14 folder. You’ll then be prompted to give it a prefix destination, followed by the opportunity to provide additional configuration parameters. For my installation I provided parameters for SSL, Web-Dav, RealIP (handy for Backend work), and the GZip static module. I also took the opportunity to exclude the mail protocols normally included with Nginx.

The site you are currently viewing is running off Nginx 0.8.14 with the configuration above (plus a few modules not shown above).

Nginx Advanced Install 3

Once finished, Passenger will inform you that the Nginx configuration file has already been modified to load the Passenger module.

To verify Nginx is installed, you can check it’s version (you may need to add /opt/nginx/sbin to the PATH).

# nginx -V
nginx version: nginx/0.8.14
built by gcc 4.3.2 (Debian 4.3.2-1.1)
configure arguments: --prefix=/opt/nginx --with-pcre=/tmp/pcre-7.8
 --add-module=/opt/ruby/lib/ruby/gems/1.9.1/gems/passenger-2.2.5/ext/nginx
 --with-http_ssl_module --with-http_dav_module --without-mail_pop3_module
 --without-mail_imap_module --without-mail_smtp_module --with-http_realip_module
 --with-http_gzip_static_module

Continue onto the next page to see how to load a start/stop script into init.d and load up your first Python (WSGI) application.

5 comments

  1. Hongli Lai says:

    Hi kbeezie, good writeup. 🙂 I just published a blog article about Phusion Passenger and Python today. Maybe you’d care to comment? http://izumi.plan99.net/blog/index.php/2009/11/21/phusion-passenger-for-python/

    “WeÂ’ll need to download and compile Ruby version 1.9.1 patch level 129. While this is not the latest, IÂ’ve had unconfirmed reports that anything newer than p129 is not fully compatible with Passenger.”

    This is correct. Later versions of 1.9.1 have bugs in the ‘tempfile’ library. These bugs have been fixed in Ruby’s SVN repository but so far there hasn’t been a 1.9.1 release containing the bug fixes.

    By the way, it’s not necessary to install Rails in order to use Phusion Passenger. Rails is only required if you deploy Rails apps.

  2. vanderkerkoff says:

    kbeezie, form some reason sudo is not finding ruby

    any ideas?

  3. kbeezie says:

    Without using sudo, try executing ruby -v to see if anything shows up at all, if not try ‘which ruby’. If nothing still shows up then either the PATH isn’t configured correctly to Ruby, or Ruby itself isn’t properly installed. ‘sudo’ itself doesn’t find commands per se, but is simply a way of saying ‘I want to run the following command as a super-user or root’.

  4. Jay States says:

    Hrm? Why, I’ll assuming that you’ve not seen the uwsgi project? This is much better for python/django/pylons – http://projects.unbit.it/uwsgi/

    Good Luck

  5. kbeezie says:

    Note the date of Nginx’s support for uwsgi and the date of said article.