FreeBSD: Start / Stop / Restart Nginx Web Server

by Vivek Gite [Last updated: October 9, 2008]

Q. 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?

A. FreeBSD comes with Nginx startup script located at /usr/local/etc/rc.d directory.

Update /etc/rc.conf

All you have to do is add following line to your /etc/rc.conf file:

nginx_enable="YES"
Once added use the following command to control nginx web server. You must be root user to control nginx.

Start Nginx Web Server Command

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

Stop Nginx Web Server Command

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

Restart Nginx Web Server Command

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

Test Nginx config file for errors

The -t option will just test the configuration file. nginx checks configuration for correct syntax and then try to open files referred in configuration.
# 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

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

Continue reading rest of the Nginx Webserver Tutorial series (TOC):
  1. FreeBSD Install Nginx Webserver
  2. FreeBSD: Start / Stop / Restart Nginx Web Server
  3. FreeBSD: Nginx FastCGI PHP Configuration
  4. FreeBSD: Nginx Virtual Hosting Configuration
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , ,

Previous post: Linux Gnome: Networkmanger Connects To Wrong Default Wireless Access Point

Next post: FreeBSD Install Munin Network and System Monitoring Application