37

I've installed and configured nginx server on my Mac from MacPorts

  1. sudo port install nginx
  2. Followed the recommendation from the port installation console and created the launchd startup item for nginx, then started the server.
  3. Renamed nginx.conf.example to nginx.conf and renamed mime.types.example to mime.types.

It works fine, but I couldn't stop it.

I tried sudo nginx -s stop, but this doesn't stop the server, I can still see "Welcome to nginx!" page in my browser on http://localhost/; also I still see master and worker processes of nginx with ps -e | grep nginx.

What is the best way to start/stop nginx on Mac?

BTW, I've added "daemon off;" into nginx.conf - as recommended by various resources.

Alex Kaushovik
  • 543
  • 1
  • 4
  • 10

6 Answers6

66
# nginx -h
...
-s signal     : send signal to a master process: stop, quit, reopen, reload
...
SaveTheRbtz
  • 5,621
  • 4
  • 29
  • 45
  • When I installed nginx with MacPorts, the above command didn't work - I wasn't giving me an error, but the server kept running. But when I wiped nginx clean and reinstalled it as part of passenger nginx module installation, it works now: I can do "nginx -s stop" and it really stops the server. Thank you! – Alex Kaushovik May 18 '10 at 14:28
  • 2
    using `nginx -s stop` worked for me but then i wasn't able to restart my server using either `nginx -s reopen`, `nginx -s reload`, `nginx -s start` or `nginx -s restart` ? How to restart? Nevermind, just executing the program `$ sudo /usr/local/sbin/nginx` restarts it. – tim peterson Sep 12 '12 at 00:37
  • @timpeterson `restart` or `reload` works on ... working server, if you are stoping it you just need to start it with common 'no-signal' `nginx` command. – biesior Nov 23 '12 at 11:07
16

This command stops also stops nginx.

sudo nginx -s stop 
HourGlass
  • 261
  • 2
  • 3
8

The correct way to do this for Nginx installed via MacPorts:

  • Start: sudo port load nginx
  • Stop: sudo port unload nginx

OS X uses launchd so the process of starting/stopping daemons is slightly different.

R. van Twisk
  • 181
  • 1
  • 2
4

Look at the PID of master process and do

kill -QUIT <master_pid>
Alexander Azarov
  • 3,510
  • 20
  • 19
3

You may try the following:

ps -lef|grep -i nginx:|awk '{ print $2}'|xargs kill -9
Diamond
  • 8,791
  • 3
  • 22
  • 37
thinkhy
  • 131
  • 2
0

Since you installed it following the steps given by macports, I guess you added it to services started at boottime. Have you tried

launchctl unload /Library/LaunchDaemons/org.macports.nginx.plist

to stop the Nginx daemon?

You could also have a try with

sudo port unload nginx
denis
  • 1
  • 1