Last active
September 6, 2022 05:49
-
-
Save ninjarobot/efa4bcb91d558fa25691691602316600 to your computer and use it in GitHub Desktop.
Building nginx for macOS without homebrew
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default target so running 'make' by itself wll download and build nginx | |
build: nginx | |
cd nginx && ./configure --with-pcre=../pcre2 && make | |
nginx: pcre2 | |
curl -O https://nginx.org/download/nginx-1.21.6.tar.gz | |
tar -xzvf nginx-*.tar.gz | |
mv nginx-*/ nginx | |
rm nginx-*.tar.gz | |
pcre2: | |
curl -OL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.gz | |
tar -xzvf pcre2-*.tar.gz | |
mv pcre2-*/ pcre2 | |
rm pcre2-*.tar.gz | |
# clean removes files used to build nginx to allow for a fresh build | |
clean: | |
rm -rf nginx* *.tar.gz pcre2* | |
# install requires elevated permissions and installs to the default /usr/local/nginx | |
install: build | |
cd nginx && sudo make install | |
# some handy symlinks | |
symlinks: | |
ln -s /usr/local/nginx/logs/access.log access.log | |
ln -s /usr/local/nginx/conf/nginx.conf nginx.conf | |
ln -s /usr/local/nginx/logs/error.log error.log | |
# purge will stop nginx and remove everything created when installing | |
purge: clean | |
rm -f *.log nginx.conf | |
sudo /usr/local/nginx/sbin/nginx -s quit | |
sudo rm -rf /usr/local/nginx | |
# backup makes a copy of nginx.conf | |
backup: | |
cp /usr/local/nginx/conf/nginx.conf backup.nginx.conf | |
# restore puts the backup of nginx.conf back into place | |
restore: | |
sudo cp backup.nginx.conf /usr/local/nginx/conf/nginx.conf | |
start: | |
sudo /usr/local/nginx/sbin/nginx | |
stop: | |
sudo /usr/local/nginx/sbin/nginx -s quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since nginx is so lightweight, I hate to depend on having homebrew to install it on macOS (plus it breaks sometimes), so I made a Makefile for it instead (works on both M1 and Intel Macs). Here's a quick guide:
make install
Downloads the source, builds it, and installs it to
/usr/local/nginx
. This will usesudo
to copy files to/usr/local
, so you'll be prompted for a password. Don't run it by itself assudo
or the source download and build artifacts will all be created asroot
.make purge
Removes the downloaded source and build artifacts, stops nginx, and removes it totally from your system. Requires
sudo
to remove it, so you'll be prompted.make clean
Just removes the downloaded source and build artifacts. It doesn't remove the installation.
make start
Starts nginx. This also uses
sudo
and you'll be prompted for a password.make stop
Stops nginx. Also uses
sudo
.make backup
You're doing local development and probably will want to backup your nginx.conf from time to time. This just copies it to your current directory so you can purge your build and still have your configuration around.
make restore
Restores that backup, if you have one.