Skip to content
Runbook

Install Nginx on macOS

High-performance web server, reverse proxy, load balancer and HTTP cache.

Toolweb-serverreverse-proxyload-balancerhttpproxy

Installation

Nginx (Homebrew) · Homebrew
brew install nginx

Homebrew configures Nginx to listen on port 8080 by default (no root required).

Verify the installation

Verify
nginx -v

Service

Start
brew services start nginx
Stop
brew services stop nginx
Status
brew services info nginx
Restart
brew services restart nginx

Important files

TypePathDescription
config/opt/homebrew/etc/nginx/nginx.confMain configuration file (Apple Silicon; /usr/local/etc on Intel).
config/opt/homebrew/etc/nginx/serversPer-site configuration directory (included by nginx.conf).
log/opt/homebrew/var/log/nginxAccess and error logs.

Default ports

8080

Command-line tools

  • nginxThe server binary; also used for control (nginx -s reload|stop).

Uninstall

Uninstall
brew services stop nginx
brew uninstall nginx

Good to know

  • Homebrew's Nginx listens on http://localhost:8080 by default, not port 80, so it runs without root.
  • To serve on port 80, change the listen directive and start with sudo (sudo nginx or sudo brew services start nginx).
  • Test the configuration with nginx -t before reloading with nginx -s reload.

Installation with Homebrew

brew install nginx installs Nginx and a default configuration that listens on port 8080 (not 80), so it can run without root. Start it as a service with brew services start nginx, then browse http://localhost:8080.

Configuration

The main file is /opt/homebrew/etc/nginx/nginx.conf (Apple Silicon; /usr/local/etc on Intel). Add per-site files under /opt/homebrew/etc/nginx/servers. Validate with nginx -t, then nginx -s reload.

Serving on port 80

To listen on the standard HTTP port, change listen 8080; to listen 80; and start Nginx with elevated privileges (sudo nginx), since ports below 1024 require root.