FreeBSD Start / Stop / Restart Nginx Web Server

last updated in Categories , , ,

How do I start / stop / restart Nginx webserver under FreeBSD operating systems? How do I test Nginx web server config file syntax before restarting my server?

Nginx is free and open-source software. It is an alternative to the Apache webserver. It is a small and fast server that supports both static and dynamic web page serving. This page shows how to start, stop, or restart Nginx on FreeBSD operating systems.


FreeBSD Start / Stop / Restart Nginx Web Server Command

Your FreeBSD server comes with Nginx startup script located at /usr/local/etc/rc.d directory. One can control it using the service command too. You must run the following command as the root user.

Start Nginx Web Server Command

# /usr/local/etc/rc.d/nginx start
# service nginx start

Stop Nginx Web Server Command

# /usr/local/etc/rc.d/nginx stop
# service nginx stop

Restart Nginx Web Server Command

# /usr/local/etc/rc.d/nginx restart
# service nginx restart

Test Nginx config file for errors

Pass the -t option to the nginx and it will just test the configuration file for syntax errors. The nginx server checks configuration for correct syntax and then try to open files referred in configuration. Hence, type the following command:
# nginx -c /usr/local/etc/nginx/nginx.conf -t
Sample output:

?2008/10/09 19:24:26 [info] 52494#0: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
2008/10/09 19:24:26 [info] 52494#0: the configuration file /usr/local/etc/nginx/nginx.conf was tested successfully

The -c /path/to/config/file specifies which configuration file Nginx should use instead of the default. Once satisfied with result, restart / start the Nginx service as follows:
# /usr/local/etc/rc.d/nginx start
# service nginx start

Update /etc/rc.conf under FreeBSD

All you have to do is add following line to your /etc/rc.conf file, run:
sudo vim /etc/rc.conf
Append or update as follows to enable nginx service at boot time:
## turn on nginx at boot time ##

Once added use above commands to control nginx web server. Remember, you must be root user to control nginx server.

How to Start, Stop, or Restart Nginx on FreeBSD

Another option is to directly send signal to a master FreeBSD nginx process using the following syntax:
# /usr/local/sbin/nginx -s [stop|quit|reopen|reload]
For instace, reload the nginx server, run:
# /usr/local/sbin/nginx -s reload
FreeBSD Start, Stop, Restart Nginx Web Server Commands


This page explained how to start, stop, and restart the Nginx web server on FreeBSD Unix operating systems.


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at

Historical Comment Archive

2 comment

    Still, have a question? Get help on our forum!