Skip to content

Instantly share code, notes, and snippets.

@beatfactor
Last active December 3, 2023 13:20
Show Gist options
  • Star 67 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save beatfactor/a093e872824f770a2a0174345cacf171 to your computer and use it in GitHub Desktop.
Save beatfactor/a093e872824f770a2a0174345cacf171 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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
Copy link

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

@Dragon-Of-Dojima
Copy link

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

@pleminh
Copy link

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
Copy link

fuse98 commented Jul 23, 2019

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

@KarmitoHerry
Copy link

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
Copy link

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
Copy link

philipb commented Apr 17, 2020

This was helpful. I've used it.

@sachinprabhuk
Copy link

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

@SofijaErkin
Copy link

@henkosasih have you used "sudo"?

@SofijaErkin
Copy link

@sachinprabhuk please just this command to take your updated nginx.conf:
sudo /usr/local/nginx/sbin/nginx -t -c /usr/local/etc/nginx/nginx.conf

sudo nginx -s reload

Also, use this command to check which conf your servers are using? default or your updated?
ps -ef|grep nginx

@SwannHERRERA
Copy link

@henkosasih have you used "sudo"?
Personally I had to use sudo because I did not have access to the /usr/local folder

@vladosnik
Copy link

vladosnik commented Sep 10, 2022

i dont have src folder in usr/local what should i do?

@costika1234
Copy link

https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz is no longer available. Use https://ftp.exim.org/pub/pcre/pcre-8.41.tar.gz instead.

@anthumchris
Copy link

Here's a one-liner that automatically uses the latest versions and includes the Nginx JavaScript module (njs):

@Albertocrypto
Copy link

when installing Nginx with sudo gives me this error, can anybody help me please:

/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile
cd ../pcre-8.41/
&& if [ -f Makefile ]; then /Library/Developer/CommandLineTools/usr/bin/make distclean; fi
&& CC="cc" CFLAGS="-O2 -pipe "
./configure --disable-shared
/bin/sh: line 0: cd: ../pcre-8.41/: No such file or directory
make[1]: *** [../pcre-8.41//Makefile] Error 1
make: *** [build] Error 2

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