Mac OS X's kernel is based on Mach and Open BSD, which is a Unix-based system. It used to be very convenient to compile native C code on Mac OS X, until Snow Leopard. From Snow Leopard until now, it becomes worse and worse with each new version of Mac OS X. Yosemite marked the worst debacle of Mac OS X to date, but in term of compiling C native code, El Capitan and macSierra are not much better either. It looks like Tim Cook tries to alienate all professional developers from using Mac.

I really have hard time when I compile nginx with openssl on Mac OS X, both El Capitan and macSierra. So I document it here.

 

Download the latest file from nginx site: http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.11.10.tar.gz

Extract the file:

tar -xzvf nginx-1.11.10.tar.gz

After you down load nginx, you also need to download openssl source from https://www.openssl.org/source/, extract the file, build openssl, and keep the source directory for further use, when you build nginx.

./config --prefix=/opt/openssl

make

sudo make install

 

The nginx compiling process expect that there will be "include" and "lib" with include files and lib files in <OPENSSL SOURCE>/.openssl

You have to manually create the directory ".openssl" there, and copy the needed files from "/opt/openssl" that you already build above.

Go into the directory where you just extract the file, run the following command:

./configure --prefix=/opt/nginx --with-http_ssl_module --with-ipv6 --with-openssl=<PATH TO OPENSSL SOURCE>

make -stdlib=libstdc++

sudo make install

Then you are ready to run nginx from /opt/nginx/sbin

The command "make" with the option "-stdlib=libstdc++" compiles and links nginx to correct platform target.