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.
sudo nginx -s stop && sudo nginx
Reload the Nginx configuration file.
sudo nginx -s reload
Table of Contents
- 1. Restart the Nginx on macOS
- 2. Reload the Nginx configuration file on macOS
- 3. Verify the Nginx Restart
- 4. References
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
sudo nginx -s stop
1.2 Start the Nginx Service
sudo nginx start
1.3 Stop and start the Nginx service in one command (restart the Nginx service)
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.
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.
sudo nginx -s reload
3. Verify the Nginx Restart
It’s good practice to verify the Nginx service has restarted successfully
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.
brew services restart nginx
4. References
The post How to restart Nginx on macOS appeared first on Mkyong.com.