I’m using Mac. I used ps -ef | grep nginx
which returned the following result.
$ ps -ef | grep nginx
0 74428 1 0 3:44PM ?? 0:00.01 nginx: master process nginx -c /usr/local/etc/nginx/nginx.conf
-2 74483 74428 0 3:47PM ?? 0:00.00 nginx: worker process
501 75545 75489 0 4:31PM ttys003 0:00.00 grep nginx
Does it mean the Nginx is running? Is there any other reliable way to check if Nginx is running?
Additionally, does nginx restart automatically every time the machine restarts?
5
Answers
The output you provided shows that nginx is indeed running on your Mac.
If you installed nginx with Homebrew, you can use:
You will get a similar output:
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.
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."
netstat -an | grep 80
to check if a process is listening on port 80, which is the default port for Nginx.lsof -i :80
to check if any process is using port 80.sudo nginx -s status
that will give you the status of Nginx.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 plist file called nginx.plist in the directory
/Library/LaunchDaemons/
with the following content:Yoiu might have to change the path inside the element.
Load the plist file using the launchctl command :
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:
-s
checks to see if the PID file "exists and has a size greater than zero"