Running and Stopping Nginx
Be sure to configure nginx first.
Starting Nginx
1. nginx may not be in your path. Test with ‘which’:$ which nginx
2. If it says ‘no nginx in…’ then nginx is most likely in /usr/local/nginx/sbin. If you like, you can add this to your path, or use the full path (/usr/local/nginx/sbin/nginx) instead of just ‘nginx’ in the command below
3. Start nginx:$ nginx -c ~/etc/nginx.conf
4. Test your site (your Mongrel instances will also need to be started)
5. If it works correctly, add the nginx & mongrel commands to your rc.local
Killing nginx
Nginx doesn’t have a nice way to shut down, so you have to use Unix’s kill command to stop it. Of course, you need to know the PID of the nginx process.
So, here’s a confusing one liner that you can copy & paste into your ssh session that will kill any nginx processes you have running:
$ ps x | awk '/[^\]]nginx: m/ {print $1}' | xargs kill
Or try this, it’s easier (-v for verbose, -i for ask you nicely):
$ killall -u $USER -v -i nginx
More generally, you can look up the PIDs of the nginx master processes (when you kill a master process, all the worker processes die as well) using ps x and then kill them yourself using kill 7777 (for a PID of 7777).