Installing Passenger + Nginx on a Linux/Unix production server
for Meteor apps + generic installation through source tarball
On this page, we will install Passenger. After installing Passenger we can begin with deploying the app.
Table of contents
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.
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
servicescript, your config files are at places where you expect them, etc.
- Consider using Passenger Standalone in a reverse proxy configuration to Nginx. Passenger Standalone + reverse proxy is fully supported and supports the same features as Passenger's Nginx integration mode.
If you understand this and choose to use Passenger with its Nginx integration mode, then read on. :-)
Step 1: download and extract tarball
Download the latest Passenger source tarball.
Extract the tarball to some place permanent. Replace X.X.X with the Passenger version, and
/somewhere-permanent with the actual directory path that you want to extract to.
/opt is usually a good directory.
$ tar -xzvf passenger-X.X.X.tar.gz -C /somewhere-permanent
Step 2: install Ruby
Passenger supports multiple languages and its core is written in C++, but its installer and administration tools are written in Ruby, so you must install Ruby.
Even though Ruby is required, Ruby will normally not be loaded during normal operation unless you deploy a Ruby web application on Passenger. Passenger's dependency on Ruby is very minimal. See Lightweight Ruby dependency for details.
sudo apt-get update sudo apt-get install -y ruby rake
|Red Hat, CentOS, Fedora, ScientificLinux, Amazon Linux||
Enable EPEL, then run as root:
yum install -y ruby rubygem-rake
sudo pacman -S ruby
|Mac OS X||No action needed. Ruby is installed by default.|
|Other operating systems||Install Ruby from the Ruby website.|
Step 3 (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:
sudo apt-get purge nginx nginx-full nginx-light nginx-naxsi nginx-common sudo rm -rf /etc/nginx
|Red Hat, CentOS, Fedora, Scientific Linux, Amazon Linux||
sudo yum remove nginx sudo rm -rf /etc/nginx
Step 4: add Passenger to PATH
Add the Passenger
bin directory to your PATH, so that your shell can locate the Passenger commands.
Open your shell's system-wide startup file. If you're using bash, this is usually
/etc/bash.bashrc. Inside that file, add this to the end:
PATH=/somewhere-permanent/passenger-X.X.X/bin:$PATH export PATH
Again, replace X.X.X with the Passenger version, and
/somewhere-permanent with the actual directory path.
When you're done, restart all your shells so that your new PATH takes effect.
Step 5: run the Passenger Nginx module installer
Run the Passenger Nginx module installer and follow the on-screen instructions:
Step 6: validate installation
After installation, please validate the install by running
sudo passenger-config validate-install. For example:
$ sudo passenger-config validate-install * Checking whether this Phusion Passenger install is in PATH... ✓ * Checking whether there are no other Phusion Passenger installations... ✓
All checks should pass. If any of the checks do not pass, please follow the suggestions on screen.
Finally, check whether Nginx has started the Passenger core processes. Run
sudo passenger-memory-stats. You should see Nginx processes as well as Passenger processes. For example:
$ sudo passenger-memory-stats Version: 5.0.8 Date : 2015-05-28 08:46:20 +0200 ... ---------- Nginx processes ---------- PID PPID VMSize Private Name ------------------------------------- 12443 4814 60.8 MB 0.2 MB nginx: master process /usr/sbin/nginx 12538 12443 64.9 MB 5.0 MB nginx: worker process ### Processes: 3 ### Total private dirty RSS: 5.56 MB ----- Passenger processes ------ PID VMSize Private Name -------------------------------- 12517 83.2 MB 0.6 MB PassengerAgent watchdog 12520 266.0 MB 3.4 MB PassengerAgent server 12531 149.5 MB 1.4 MB PassengerAgent logger ...
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.
As explained earlier in the introductory notes, you can't use an init script like
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.
Nginx's configuration files are then located in
/opt/nginx/conf. Its log files are located in
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:
$ ps auxw | grep nginx root 25817 0.0 0.1 43248 1172 ? S Jan01 0:00 nginx: master process /opt/nginx/sbin/nginx www-data 25818 0.0 0.3 44240 3484 ? S Jan01 0:02 nginx: worker process
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 is the same as shutting down Nginx, and starting it again. For example:
$ sudo kill $(cat /opt/nginx/logs/nginx.pid) $ sudo /opt/nginx/sbin/nginx
How do I install Nginx with additional modules?
The installer is interactive. How do I install in an automated, non-interactive manner?
Please refer to Non-interactive, automatic, headless installs or upgrades.
Some of the dependent libraries are installed in non-standard locations. How do I allow the compiler to find them?
Please refer to Customizing the compilation process.
How do I pass additional flags to the compiler?
Please refer to Customizing the compilation process.
Now that you have installed Passenger, you are ready to deploy your Meteor application on the production server!