Question 1: Is Nginx running?
Yes, the output you get indicates that Nginx is currently running on your mac.
The first line in the output shows the master process with PID 74428 and the second line shows a worker process with PID 74483.
Question 2: Other ways to find out if Nginx is running.
- Use the command
nginx -t
which will test the configuration files for syntax errors.
If the configuration is valid, it will display the message "nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful."
- Using the command
netstat -an | grep 80
to check if a process is listening on port 80, which is the default port for Nginx.
- Using the command
lsof -i :80
to check if any process is using port 80.
- By using the command
sudo nginx -s status
that will give you the status of Nginx.
- Third party tools like Nagios (open-source).
Question 3: Does nginx restart automatically every time the machine restarts?
By default, Nginx does not automatically start at boot time on macOS, so it will not automatically restart after a machine restart. You can use launchd or launchctl to set up Nginx as a service so that it starts automatically on boot.
If you wish to do so. 2 ways.
- Create a launchd plist file and use launchctl command to load it.
Create a plist file called nginx.plist in the directory
/Library/LaunchDaemons/
with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>nginx</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/nginx</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>_www</string>
<key>GroupName</key>
<string>_www</string>
<key>StandardErrorPath</key>
<string>/var/log/nginx/error.log</string>
<key>StandardOutPath</key>
<string>/var/log/nginx/access.log</string>
</dict>
</plist>
Yoiu might have to change the path inside the element.
Load the plist file using the launchctl command :
sudo launchctl load /Library/LaunchDaemons/nginx.plist
Use the command "launchctl list | grep nginx" to verify that Nginx is running.
To remove the plist file and stop Nginx from starting automatically on boot:
sudo rm /Library/LaunchDaemons/nginx.plist
- If you have used Homebrew to install Nginx you could you the following commands
brew services info nginx // status answer to question 2
brew services start nginx // start Nginx
brew services enable nginx // configure Nginx to start automatically on boot
brew services list // verify that Nginx is set to automatically run on boot
brew services stop nginx // stop Nginx
brew services disable nginx // remove the service so not to run Nginx on boot