Where apps hide your files
macOS does not include nginx, so the config file is wherever you installed it, and for most people that is Homebrew. The path depends on whether your Homebrew lives in /opt/homebrew or /usr/local.
With Homebrew on an Apple silicon Mac:
/opt/homebrew/etc/nginx/nginx.conf
With Homebrew on an Intel Mac, or a Homebrew running under Rosetta:
/usr/local/etc/nginx/nginx.conf
Homebrew's formula page describes this as $HOMEBREW_PREFIX/etc/nginx/nginx.conf, where the prefix is /opt/homebrew or /usr/local. The surest way to get the exact path for your install is to ask nginx:
nginx -t
That tests the config and prints a line such as the configuration file ... syntax is ok, naming the file it read. If the command is not found, nginx is not on your PATH, which usually means it is not installed from Homebrew (see below).
Finder hides the top-level /opt and /usr folders, so you cannot click your way there. Use Go > Go to Folder (⇧⌘G) and paste /opt/homebrew/etc/nginx, or from Terminal:
open "$(brew --prefix)/etc/nginx"
To edit in your usual editor, open -e uses TextEdit and code opens VS Code if you have its command installed. These files belong to your user, so no sudo is needed for a Homebrew install.
| Path | What it is |
|---|---|
nginx.conf | The main file. Port, worker settings, and the default server block. |
servers/ | Per the Homebrew formula, nginx loads every file in this folder, so you can add one file per site without touching nginx.conf. |
mime.types | File extension to content type table. |
fastcgi_params, scgi_params, uwsgi_params | Parameter sets for backends. Used by include lines. |
*.default | Pristine copies shipped with nginx. Compare against them if you break something. |
The formula page also says the default port is set to 8080 in nginx.conf, so nginx can run without sudo, and that the document root is $HOMEBREW_PREFIX/var/www. Open http://localhost:8080 to check it is serving.
Test first. A broken config will not load.
nginx -t
Then apply it without dropping connections:
nginx -s reload
nginx's own beginner's guide describes reload as checking the new syntax and, if it passes, starting new workers while the old ones finish their requests. If the check fails, nginx keeps the old configuration.
If you started nginx with Homebrew's service manager, nginx -s reload still works. brew services restart nginx also applies the change, but it stops and starts the server, dropping open connections.
Logs go where the error_log and access_log lines in nginx.conf say. Look there rather than guessing, for example with grep -n _log /opt/homebrew/etc/nginx/nginx.conf. Homebrew builds nginx with $HOMEBREW_PREFIX/var/log/nginx/error.log and access.log as the defaults, which apply while those lines in the stock nginx.conf stay commented out.
nginx's own documentation says nginx.conf is placed in /usr/local/nginx/conf, /etc/nginx or /usr/local/etc/nginx, depending on how it was built. A source build uses /usr/local/nginx/conf unless you passed a different prefix. MacPorts builds nginx to read /opt/local/etc/nginx/nginx.conf, with logs in /opt/local/var/log/nginx, according to its Portfile. Running nginx -V prints the build options, including the config path, and is safe to run.
nginx was not installed on the Mac used for this guide, so these paths come from Homebrew's formula, the MacPorts Portfile and nginx's documentation. A Mac can have both Homebrew prefixes, which is common after migrating from an Intel Mac. If nginx -t names a file in the prefix you did not expect, you are running the other Homebrew's copy; which -a nginx lists every copy on your PATH.
For a Homebrew install, the formula says nginx loads every file in the servers folder. That means a new site can be one small file there, such as servers/mysite.conf, holding a server block with a listen port, a server_name and a root folder. Run nginx -t after saving, then nginx -s reload. Keeping each site in its own file is easier to undo than editing the main nginx.conf, and a mistake only affects the file you just added: delete or rename it, test again and reload.
The default port of 8080 needs no special rights, and port 80 often works without sudo too. On the Mac used for this guide (macOS Sequoia), an ordinary user could listen on a port below 1024 on all addresses, which is what a plain listen 80; does, but not on 127.0.0.1 alone. So listen 127.0.0.1:80; needs nginx started as root, and a Permission denied error on startup points to this. Whichever you choose, check with nginx -t before reloading.
/opt/homebrew and /usr/local/etc are system-level folders, and Spotlight and Finder searches leave results from them out. A search for nginx.conf in Finder will often return nothing even though the file exists.
Typing nginx.conf into Everywhere lists every copy on the Mac, including nginx.conf.default and the stray backup you forgot you made, with the folder shown beside each. ⌘T opens a Terminal in the folder of the one you pick. It matches names only, so it will not show which copy nginx is actually using; nginx -t answers that.
/opt/homebrew/etc/nginx/nginx.conf on Apple silicon and /usr/local/etc/nginx/nginx.conf on Intel. Running nginx -t prints the path of the file it actually reads.
Run nginx -t to test the file, then nginx -s reload. If you use Homebrew's service manager, brew services restart nginx works too.
Homebrew's formula sets the default port to 8080 in nginx.conf so nginx can run without sudo. Check the listen line in your own file.
The file sits in a system-level Homebrew folder that Finder and Spotlight searches skip. Use Go to Folder (⇧⌘G) with the path above.
Everywhere keeps track of every file on your Mac — including the folders Spotlight hides and drives you have unplugged. Free for a day, then $19 once.
Version 2.20.3 · macOS 13+ · 4.7 MB · notarised