FreeBSD Install Nginx Webserver

How do I install an Nginx webserver under a FreeBSD Unix operating system?

nginx [engine x] is a HTTP server, reverse proxy and mail proxy server written by Igor Sysoev. It is a lightweight web server, licensed under a BSD-like license. It the fastest growing and one of the most popular web server.

Update FreeBSD ports tree

Type the following command to update FreeBSD tree, enter:
# portsnap fetch update
Sample outputs:

Looking up mirrors... 7 mirrors found.
Fetching public key from done.
Fetching snapshot tag from done.
Fetching snapshot metadata... done.
Fetching snapshot generated at Fri Sep  9 05:32:42 IST 2016:
16ed4abfc9b7777b9ca5999867f5bfa793c7e1c1902b89100% of   71 MB 3978 kBps 00m18s
Extracting snapshot... done.
Verifying snapshot integrity... 

Install Nginx using FreeBSD ports

Type the following command to install the Nginx web server port:
# cd /usr/ports/www/nginx/
# make install clean

Fig.01 FreeBSD install Nginx Using the Port
Fig.01 FreeBSD install Nginx Using the Port

Make sure you select important option such as REWRITE_MODULE, SSL_MODULE and others as per your requirements.

Install nginx using the pkg command

Add the binary package using the following command:
# pkg install nginx
Sample outputs:

Fig.02: Add the package
Fig.02: Add the package

Turn on Nginx Webserver Service

Type the following command to turn on Nginx server
# echo 'nginx_enable="YES"' >> /etc/rc.conf

How do I start an nginx server?

To start Nginx, enter:
# /usr/local/etc/rc.d/nginx start
# service nginx start
Sample outputs:

Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.

How do I stop an nginx server?

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

How do I restart an nginx server?

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

How do I reload an nginx server after config file changes?

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

Important Information about Nginx webserver on a FreeBSD

  • Nginx Default configuration file: /usr/local/etc/nginx/nginx.conf
  • Nginx Default http / https port: 80 / 443
  • Nginx Default error log file: /var/log/nginx-error.log
  • Nginx Default access log file: /var/log/nginx-access.log
  • Nginx Default DocumentRoot: /usr/local/www/nginx/
  • Nginx service command: service nginx (start|stop|restart|reload|configtest|upgrade|gracefulstop|status|poll)

Testing the setup

Type the following url in your web-browser:
OR your domain name:
Sample outputs:

Fig.03: Nginx in action
Fig.03: Nginx in action
Posted on: October 16, 2017, by :  | 24 views

Leave a Reply