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

Prerequisites

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.

5. To fix the error, visit the tutorial page and read “Building nginx from Sources”, in which you can find the link of PCRE library.

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

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

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

9. 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.pid"

  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”.

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

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

12. Launch nginx “sudo ./nginx”

The nginx is successfully running now!

nginx running

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

 

  • Vasil

    Thanks for putting this together, it’s one of the good links on this topic.

    Couple of notes that may make it easier / save troubleshooting for some people:

    1. Correcting a kind of obvious typo in Step 8 because of autocorrected dashes, in case anyone uses it as copy/pasted: instead of “sudo ./configure –with-pcre=path” it should be “sudo ./configure –with-pcre=path” with two hyphens of course.

    2. For PCRE you may want to mention a step with ./configure, make, sudo make install

    3. When getting PCRE there may be some confusions, as the SourceForge page shows a link with the latest version (pcre2-10.23) and then the list of other pcre versions (like pcre-8.40).

    Using pcre2-10.23 resulted in errors for me when building nginx-1.10.1 at a line with #include however using a version like pcre-8.40 worked ok.
    Here is the link to get it, as listed on the SourceForge page.

  • Raj

    followed this URL https://github.com/Homebrew/homebrew-nginx to successfully install 1.9.7 Mainline version.. thx for your time

  • Raj

    Hi Desmond, Have you tried Mainline version on Mac – OS X El Capitan (version 10.11) https://fak3r.com/2015/09/29/howto-build-nginx-with-http-2-support/

    I am finding one issue during the make operation.

    RajRajen:nginx-1.9.7 rajrajen$ make

    /Applications/Xcode.app/Contents/Developer/usr/bin/make -f objs/Makefile

    cd /usr/local/Cellar/openssl/1.0.2d_1

    && if [ -f Makefile ]; then /Applications/Xcode.app/Contents/Developer/usr/bin/make clean; fi

    && ./config –prefix=/usr/local/Cellar/openssl/1.0.2d_1/.openssl no-shared

    && /Applications/Xcode.app/Contents/Developer/usr/bin/make

    && /Applications/Xcode.app/Contents/Developer/usr/bin/make install LIBDIR=lib

    /bin/sh: ./config: No such file or directory

    make[1]: *** [/usr/local/Cellar/openssl/1.0.2d_1/.openssl/include/openssl/ssl.h] Error 127

    make: *** [build] Error 2

    When you try the latest version 1.9.7, please update me as well, thanks.