Skip to content
EnriqueVidal edited this page May 9, 2012 · 1 revision

Nginx installation

Setting up nginx through passenger

First install the passenger gem:

sudo gem install passenger

After the gem has been installed we need to switch to root, create a src directory and download the latest release of nginx (1.0.14 as of this writing), check the nginx download site to make sure you have the latest version.

sudo bash --login
mkdir /usr/src
cd /usr/src
curl http://nginx.org/download/nginx-1.0.14.tar.gz -o nginx.tar.gz
pv nginx.tar.gz | tar zxfp -

After running these lines you will have an uncompress copy of nginx in your /usr/src folder, it's now time to compile.

First run the passenger module installer:

passenger-install-nginx-module

You will see a prompt asking you if you wan't to automatically download and compile nginx or if you have your own copy of it (Advance):

Automatically download and install Nginx?

Nginx doesn't support loadable modules such as some other web servers do,
so in order to install Nginx with Passenger support, it must be recompiled.

Do you want this installer to download, compile and install Nginx for you?

 1. Yes: download, compile and install Nginx for me. (recommended)
    The easiest way to get started. A stock Nginx 1.0.10 with Passenger
    support, but with no other additional third party modules, will be
    installed for you to a directory of your choice.

 2. No: I want to customize my Nginx installation. (for advanced users)
    Choose this if you want to compile Nginx with more third party modules
    besides Passenger, or if you need to pass additional options to Nginx's
    'configure' script. This installer will  1) ask you for the location of
    the Nginx source code,  2) run the 'configure' script according to your
    instructions, and  3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.

We pick option 2 (cause' we're hardcore), and then we will be asked two questions.

  • Where is your Nginx source code located? /usr/src/nginx-1.0.14
  • Where do you want to install Nginx to? /opt/nginx

We're almost done, we now need to set any additional configure option we might want in this case we want gizip_static

To add it we type --with-http_gzip_static_module as extra argument and when we're asked Is this what you want? we just type yes.

We'll see a whole buch of compilation message (it takes a few minutes grab a cup of coffee), when it's done we can remove the nginx source and exit the root shell:

rm -fr nginx*
exit

Nginx auto-start (mac users only)

Create a file named /Library/LaunchDaemons/org.nginx.nginx.plist with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>nginx</string>
    <key>Program</key>
    <string>/opt/nginx/sbin/nginx</string>
    <key>KeepAlive</key>
    <true/>
    <key>NetworkState</key>
    <true/>
    <key>LaunchOnlyOnce</key>
    <true/>
  </dict>
</plist>

Then run:

sudo chown root:wheel /Library/LaunchDaemons/org.nginx.nginx.plist
sudo launchctl load /Library/LaunchDaemons/org.nginx.nginx.plist
sudo launchctl start org.nginx.nginx #this might give an error message on Lion that is safe to ignore

After this is done your copy of nginx will be running and it will start automatically when the OS starts.