How to restart nginx?

Solution 1:

The nginx package supplies a /etc/init.d/nginx script that provides the usual start|stop|restart|reload ... functionality.

/etc/init.d/nginx restart

will restart nginx

as will

service nginx restart

Edit

Here is a link to a script you can use as /etc/init.d/nginx.

Solution 2:

http://wiki.nginx.org/CommandLine

inside the links there are some command for start and stop nginx server

for starting nginx:

/usr/bin/nginx

for stoping nginx:

/usr/bin/nginx -s stop

/usr/bin depends on where you install your nginx

Solution 3:

For some reason, on the embedded system I am working on it is:

systemctl restart nginx

Solution 4:

After editing the configuration files, I restart it like this on OpenBSD:

kill -HUP `cat /var/run/nginx.pid` && date && sleep 1 && \
    tail -2 /var/www/logs/error.log ; date

The HUP signal makes it re-read its configuration files, the tail shows whether any errors have been encountered, the date puts those errors into the context (an error has occurred only if the time from date matches the time from the log), and sleep 1 ensures that there are no race conditions between reading from the log prior to nginx having had a time to write to it.

This is how it looks:

Cns# kill -HUP `cat /var/run/nginx.pid` && date && sleep 1 && tail -2 /var/www/logs/error.log ; date
Tue Feb 12 10:58:52 PST 2013
2013/02/12 10:03:35 [emerg] 8120#0: directive "set" is not terminated by ";" in /etc/nginx/conf.d/etc.ngx.grok/bxr.su.conf:226
2013/02/12 10:04:19 [emerg] 8120#0: invalid return code "$uri_def" in /etc/nginx/conf.d/etc.ngx.grok/bxr.su.conf:231
Tue Feb 12 10:58:53 PST 2013
Cns# 

The fact that the time from the log is not between times printed by date indicates that no errors have been encountered this time around, and the new configuration is a good one.