The Homebrew service control in macOS does not display if there is/are error(s) in your nginx configuration. For example if you mistakenly duplicate the declaration of "client_max_body_size" directive Homebrew service control won't give any error details or even tell you that there is error in your nginx configuration when you restarted the nginx service:
$ sudo brew services restart nginx
Password:
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)
Even if you add the verbose -v
parameter, still no hint that there's an error:
$ sudo brew services restart nginx -v
Password:
Stopping `nginx`... (might take a while)
/bin/launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Generated plist for nginx:
Label homebrew.mxcl.nginx RunAtLoad KeepAlive ProgramArguments /usr/local/opt/nginx/bin/nginx -g daemon off; WorkingDirectory /usr/local
/bin/launchctl enable system/homebrew.mxcl.nginx
/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)
The ideal is for example in CentOS, it gives you hint that there's an error:
# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
... and option to view the details about the error:
# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2018-05-24 15:31:59 +08; 25s ago
Docs: http://nginx.org/en/docs/
Process: 5371 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 3491 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Process: 6325 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
Main PID: 3741 (code=exited, status=0/SUCCESS)
May 24 15:31:58 sys.webfoobar.com systemd[1]: Starting nginx - high performance web server...
May 24 15:31:59 sys.webfoobar.com nginx[6325]: nginx: [emerg] "client_max_body_size" directive is duplicate in /etc/nginx/nginx.conf:163
May 24 15:31:59 sys.webfoobar.com nginx[6325]: nginx: configuration file /etc/nginx/nginx.conf test failed
May 24 15:31:59 sys.webfoobar.com systemd[1]: nginx.service: control process exited, code=exited status=1
May 24 15:31:59 sys.webfoobar.com systemd[1]: Failed to start nginx - high performance web server.
May 24 15:31:59 sys.webfoobar.com systemd[1]: Unit nginx.service entered failed state.
May 24 15:31:59 sys.webfoobar.com systemd[1]: nginx.service failed.
But Homebrew does not offer this. Instead, as workaround we can directly execute nginx to give us hint and details about the error:
$ sudo /usr/local/opt/nginx/bin/nginx -s reload
nginx: [emerg] "client_max_body_size" directive is duplicate in /usr/local/etc/nginx/nginx.conf:15
Note: even if you have this line of code in your nginx configuration:
error_log /var/log/nginx/nginx_error.log warn;
... it does not log any nginx configuration error(s) in /var/log/nginx/nginx_error.log
file.