Install Nginx on MacOS (Lion)

Nginx is a very fast lightweight http server that can be used as a loadbalancer or as a reverse proxy for underlying Coldfusion or Railo instances. Try it! The good news: it is very easy to install and configure. The bad news (or call it a challenge if you are not familiar with compiling applications yourself) is that it comes as source code. Do not worry. The process is really very straightforward. I will walk you through the Nginx installation on MacOSX 10.7 (Lion).

  • Download PCRE. Nginx requires PCRE (Perl Compatible Regular Expressions) to build. You can download the latest version from http://www.pcre.org.  I used the version 8.13. Save the pcre-8.13.tar.gz (or newer version) to a /usr/local/src folder. Create a new src folder if you don’t have it yet. You will need your administrator password to alter the contents of this folder.
  • Download Nginx from http://wiki.nginx.org/Install I used the version 1.1.16 which comes as nginx-1.1.16.tar.gz. Save it to to a /usr/local/src folder as well.
  • Build and install PCRE: open your Terminal app and type:
    cd /usr/local/src
    tar xvzf pcre-8.13.tar.gz
    cd pcre-8.13
    ./configure --prefix=/usr/local
    make
    sudo make install
    cd ..

    That will build and install PCRE on your system

  • Build and install Nginx: stay in Terminal and type:
    tar xvzf nginx-1.1.16.tar.gz
    cd nginx-1.1.16
    ./configure --prefix=/usr/local --with-http_ssl_module
    make
    sudo make install
  • Start Nginx. You can start it by entering
    sudo /usr/local/sbin/nginx

    Please note! You must change the server port from 80 to something else (say 81) if you already run Apache on port 80. You can find the Nginx configuration file as /usr/local/conf/nginx.conf Locate the port and change it to something else.

       server {
            listen       81;
            server_name  localhost;

Congratulations! You are running Nginx on your Mac. Don’t you like this minimalistic default homepage? In the next part I’ll discuss hooking Nginx to Railo.