Main Tutorials

How to restart Nginx on macOS

We open a Terminal and use the one-liner command sudo nginx -s stop && sudo nginx to restart the Nginx on macOS.

Restart the Nginx service.

Terminal

  sudo nginx -s stop && sudo nginx

Reload the Nginx configuration file.

Terminal

  sudo nginx -s reload

Table of Contents

P.S. Tested with macOS 13 and Nginx 1.21

1. Restart the Nginx on macOS

The Nginx has no official restart command; however, we can easily combine two commands to restart the Nginx process.

1.1 Stop the Nginx Service

Terminal

  sudo nginx -s stop

1.2 Start the Nginx Service

Terminal

  sudo nginx start

1.3 Stop and start the Nginx service in one command (restart the Nginx service)

Terminal

  sudo nginx -s stop && sudo nginx

2. Reload the Nginx configuration file on macOS

In most cases, we do not need to restart the Nginx service. We can reload the Nginx service to apply the changes if we change the Nginx configuration file.

2.1 It’s recommended to use sudo nginx -t to test the Nginx configuration file before reloading it.

Terminal

  sudo nginx -t

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

2.2 Reload the Nginx service and apply the changes made in the configuration file.

Terminal

  sudo nginx -s reload

3. Verify the Nginx Restart

It’s good practice to verify the Nginx service has restarted successfully

Terminal

ps aux | grep nginx

mkyong       6533   0.0  0.0 34121308    604 s000  S+    3:13PM   0:00.00 grep nginx
mkyong       6362   0.0  0.0 34415920   1288   ??  S     3:00PM   0:00.00 nginx: worker process
mkyong       6361   0.0  0.0 34416944   1316   ?? S     3:00PM   0:00.00 nginx: worker process
root         6360   0.0  0.0 34275376    620   ?? Ss    3:00PM   0:00.00 nginx: master process nginx

Note
If we use brew, we can use brew services to restart the Nginx service directly.

Terminal

  brew services restart nginx

4. References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments