FreeBSD Start / Stop / Restart Nginx Web Server

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


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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Adan Mar 7, 2012 @ 7:08

    I need help to uninstall nginx from my boyfriends computer!
    So can ou please help me!

  • Pretty Nov 9, 2015 @ 17:42

    Please help me to remove this nginx application from my phone screen please!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum