How to Configure and Install Nginx on Mac OS X

In this tutorial, I would like to show how to configure and install nginx on Mac OS X. My Mac system is Mavericks 10.9.2.

mac environment


You have to install Xcode command line tools.

Install Nginx

  1. Download the latest stable version – nginx 1.4.7.

  2. Unzip the downloaded package by the command “tar xvzf nginx-1.4.7.tar.gz”.

  3. “cd nginx-1.4.7”.

  4. “sudo ./configure”. There is an error displayed:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.
  1. To fix the error, visit the tutorial page and read “Building nginx from Sources”, in which you can find the link of PCRE library.

  2. Go to PCRE official site, and find the latest version of PCRE library on SourceForge.

  3. Download the package and unzip it by the command “tar xvzf pcre-8.34.tar.bz2”.

  4. Now, you can run the configure file again with the parameters  ”sudo ./configure –with-pcre=path”.

  5. Configuration is done.

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp" 

the default nginx path prefix is “/usr/local/nginx”.

  1. To install nginx, type in “sudo make install”.

  2. Find the executable file “cd /usr/local/nginx/sbin”

  3. Launch nginx “sudo ./nginx”

The nginx is successfully running now!

nginx running

If you have any questions, just email {desmond at dynamsoft dot com}.