On this page, we will install Passenger. After installing Passenger we can begin with deploying the app.

Table of contents

Loading...

Before you begin: a note about Nginx

Before you begin, you should know that installing Passenger in its Nginx integration mode involves extending Nginx with code from Passenger. However, Nginx does not support loadable modules. This means that in order to install Passenger's Nginx integration mode, it is necessary to recompile Nginx from source. And that is exactly what we will do in this installation guide.

The fact that Nginx needs to be recompiled, has some implications:

Many users installed Nginx using their operating system's package manager (yum, apt-get, etc). This Nginx is usually located in /usr/sbin/nginx, with configuration file /etc/nginx/nginx.conf. However, if you install Nginx from source, then you will end up with another Nginx installation (that has Passenger enabled) that is located somewhere else. This other Nginx installation does not look for its /etc/nginx/nginx.conf, but somewhere else.

Some people get confused by having two Nginx installations and end up editing the wrong config file. To avoid confusion, this guide will recommend you to uninstall the OS-installed Nginx before proceeding.

Init scripts, e.g. /etc/init.d/nginx and service nginx restart, are not provided by the default Nginx source code. Init scripts are actually extensions provided by the operating system's Nginx package. If you install Nginx from source, then you can't use init scripts to control Nginx anymore. Instead, you will use more generic operating system primitives to control Nginx, such as PID files and signals. Don't worry, this installation guide will teach you.

If you do not like having to recompile Nginx then there are several alternatives you can choose:

Use the Phusion Passenger APT repository (for Debian, Ubuntu) or the YUM repository (RPMs for Red Hat, CentOS) to install Passenger and Nginx. Through our APT/YUM repository, we provide a Passenger-enabled Nginx package that uses the same structure as the Nginx package provided by the OS. This means that you will be able to use the service script, your config files are at places where you expect them, etc.

Did gem install abort with a "permission denied" error? Then re-run it with
sudo.

Step 2 (optional): uninstall the OS-installed Nginx

As explained earlier in the introductory notes, you are about to install a new Nginx installation from source. If you already installed Nginx before, using the operating system's package manager, then we recommend that you uninstall that in order to avoid possible confusion caused by having multiple parallel Nginx installations. Of course, you don't have to remove the OS-installed version as long as you know what you're doing.

Here are some examples of how you can uninstall the OS-installed version:

If you do not see any Nginx processes or Passenger processes, then you probably have some kind of installation problem or configuration problem. Please refer to the troubleshooting guide.

Using Nginx

As explained earlier in the introductory notes, you can't use an init script like /etc/init.d/nginx or service nginx restart. This section teaches you how to control and how to work with the Nginx you installed.

Remember that at some point, passenger-install-nginx-module asked you where to install Nginx to, and asked you for a "prefix", right? The prefix is the directory in which this new Nginx is installed. By default, the installer picks the directory /opt/nginx. In this section we will assume that you installed to the default prefix directory. If you specified a different prefix, simply substitute /opt/nginx with the actual directory.

File locations

Nginx's configuration files are then located in /opt/nginx/conf. Its log files are located in /opt/nginx/logs.

Starting Nginx

You can start Nginx by running:

$ sudo /opt/nginx/sbin/nginx

Shutting down Nginx

You can shut down Nginx by killing its PID with the kill command. To find out what Nginx's PID is, use the ps command. For example:

Here we see that the Nginx master process has PID 25817 (you can ignore the worker process), so we run:

$ sudo kill 25817

Having to perform two steps is a bit cumbersome. Luckily, there is an easier way to do this. By default, Nginx creates a PID file in /opt/nginx/logs/nginx.pid. This PID file contains Nginx's current PID. So we can use a single command to shutdown Nginx:

$ sudo kill $(cat /opt/nginx/logs/nginx.pid)

Restarting Nginx

Restarting Nginx is the same as shutting down Nginx, and starting it again. For example: