Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Nginx on Mac OS from source (without brew)

Install Nginx on Mac OS from source

no Homebrew required

1. Download Nginx

$ cd /usr/local/src
$ curl -OL http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -xvzf nginx-1.12.2.tar.gz && rm nginx-1.12.2.tar.gz

2. Download the PCRE library

The PCRE library distribution (version 4.4 — 8.41) needs to be downloaded from the PCRE site and extracted. The rest is done by nginx’s ./configure and make. PCRE is required for the http_rewrite_module, and also for regular expressions support in the location directive.

$ curl -OL https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
$ tar xvzf pcre-8.41.tar.gz && rm pcre-8.41.tar.gz

3. Configure Nginx

See the full list of ./configure options: http://nginx.org/en/docs/configure.html.

$ cd nginx-1.12.2/

Compile nginx without SSL support

$ ./configure --with-pcre=../pcre-8.41/ 

with SSL support

Download OpenSSL sources and extract:

$ curl -OL https://www.openssl.org/source/openssl-1.1.0.tar.gz
$ tar xvzf openssl-1.1.0.tar.gz && rm openssl-1.1.0.tar.gz 

Compile Nginx:

$ cd ../nginx-1.12.2/
$ ./configure --with-pcre=../pcre-8.41/ --with-http_ssl_module --with-openssl=/usr/local/src/openssl-1.1.0

4. Install Nginx

$ [sudo] make && make install

Add the nginx binary to $PATH:

export PATH="/usr/local/nginx/sbin:$PATH"
@Kwon11

This comment has been minimized.

Copy link

@Kwon11 Kwon11 commented Oct 2, 2018

stable version of nginx when I used this article is 1.14.0

Thanks for putting this up man it was a huge help.

@YukunSun

This comment has been minimized.

Copy link

@YukunSun YukunSun commented Oct 28, 2018

In the section of "with SSL support" ,you maybe spell openssl-1.1.0g.tar.gz wrong ,it should be openssl-1.1.0.tar.gz

@rustymagnet3000

This comment has been minimized.

Copy link

@rustymagnet3000 rustymagnet3000 commented Apr 24, 2019

This is great. Did you want to write about the other option with SSL Support where you point to an existing OpenSSL install?

@NullPointing

This comment has been minimized.

Copy link

@NullPointing NullPointing commented Jul 14, 2019

how do you actually run nginx once this is all done? Everytime I try, it says "command not found"

@pleminh

This comment has been minimized.

Copy link

@pleminh pleminh commented Jul 17, 2019

how do you actually run nginx once this is all done? Everytime I try, it says "command not found"

sudo /usr/local/nginx/sbin/nginx

@fuse98

This comment has been minimized.

Copy link

@fuse98 fuse98 commented Jul 23, 2019

great job. this solved my issue, thanks a lot.

@KarmitoHerry

This comment has been minimized.

Copy link

@KarmitoHerry KarmitoHerry commented Nov 12, 2019

Can I skip install with SSL support ?

When i try to install without with SSL support. I got this error

/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile
make[1]: Nothing to be done for `build'.
/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile install
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin'
|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx'
|| mv '/usr/local/nginx/sbin/nginx'
'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
cp: /usr/local/nginx/sbin/nginx: Permission denied
make[1]: *** [install] Error 1
make: *** [install] Error 2

anyone have same problem like me ?

@henkosasih

This comment has been minimized.

Copy link

@henkosasih henkosasih commented Jan 26, 2020

Can I skip install with SSL support ?

When i try to install without with SSL support. I got this error

/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile
make[1]: Nothing to be done for `build'.
/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile install
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin'
|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx'
|| mv '/usr/local/nginx/sbin/nginx'
'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
cp: /usr/local/nginx/sbin/nginx: Permission denied
make[1]: *** [install] Error 1
make: *** [install] Error 2

anyone have same problem like me ?

use chown to give permission to folder ex: sudo chown -R [user] nginx

@philipb

This comment has been minimized.

Copy link

@philipb philipb commented Apr 17, 2020

This was helpful. I've used it.

@sachinprabhuk

This comment has been minimized.

Copy link

@sachinprabhuk sachinprabhuk commented Jun 16, 2021

This helped, but how do i configure the nginx though, i tried updating "/usr/local/etc/nginx/nginx.conf" its not taking effect.
Any suggestion?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment