78

I just installed Nginx on Mac OS X (thanks http://www.kevinworthington.com/nginx-mac-os-snow-leopard-2-minutes/), but how do I restart Nginx on Mac OS X?

Thanks!

Laura Brown
  • 813
  • 1
  • 7
  • 5
  • 3
    If you just want to restart because of an updated config then just do `sudo nginx -s reload`. – hobbes3 Mar 16 '13 at 21:26

9 Answers9

145
sudo nginx -s stop && sudo nginx
osdyng
  • 1,872
  • 1
  • 13
  • 10
55

For a one-liner, you could just do:

sudo nginx -s reload

The -s options stands for signal, and is the option you'll use to send stop, quit, reopen and reload signals to nginx.

For more info on the options, just do nginx -h for a list of all of them and their functions.

Cheers!

James Pederson
  • 651
  • 5
  • 4
  • 2
    This did not work for me so I had to actually do `sudo nginx` to get it to start. I think it had something to do with nginx already being stopped in my case. – james-see May 19 '16 at 17:40
  • 1
    Could you do `sudo nginx -s reload || sudo nginx` instead? – James Murphy Jul 01 '19 at 13:38
27

for brew installation: sudo brew services restart nginx

dimaninc
  • 371
  • 3
  • 3
  • 1
    This command dosn't work for me at all. I install nginx via brew... – kris_IV Dec 22 '18 at 18:37
  • 1
    @kris_IV what is the output? – dimaninc Dec 23 '18 at 08:29
  • 1
    after start: `brew services restart nginx` i get response: `Stopping `nginx`... (might take a while)` `==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)` `==> Successfully started `nginx` (label: homebrew.mxcl.nginx)` – kris_IV Dec 25 '18 at 11:32
  • 1
    @kris_IV and why do you think this command not working then? everything is fine according to your output – dimaninc Dec 25 '18 at 20:47
  • 1
    I know that the output is OK, but new config doesn't work at all, but when I use `sudo nginx -s stop && sudo nginx` instead everything is OK and new config work. – kris_IV Dec 26 '18 at 11:11
  • 1
    It's the right command to start via services, but sudo is not needed. Nginx can be started also by calling the executable `nginx` – funder7 Dec 15 '20 at 12:41
  • 2
    It looked good on `brew services restart nginx` – SmallChess Feb 04 '21 at 20:02
  • This wasted me hours. It looks like it worked, but it's better to just use nginx correctly rather than doing so through brew. – jscul Jul 28 '22 at 01:10
11
sudo pkill nginx   
sudo nginx

If the pkill can't be found, then install it using brew install proctools first.

Kurt Zhong
  • 269
  • 3
  • 3
8

If you are using brew:

To see all services:

brew services list

Start nginx service:

brew services start nginx

Stop nginx Service:

brew services stop nginx
nima
  • 180
  • 1
  • 4
1

sudo nginx -s quit && sudo nginx

Checkout nginx guide

Reck
  • 119
  • 2
1

Using MAMP and Nginx? Then you have an installed script:

sudo /Applications/MAMP/bin/restartNginx.sh 
PeddlePower
  • 111
  • 2
1

Just another note, if you want to start nginx with launchctl, when your Mac boots up, you can do as follows:

sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

In short, you need to put your plist file in /Library/LaunchDaemons, not in ~/Library/LaunchAgents like the Homebrew instructions. Finally, use the -w option with launchctl. For further information, follow this guide.

1

If you installed nginx with brew and you started it as a service brew services start nginx then you can issue: brew services restart nginx

doublespaces
  • 111
  • 1