How to Install Nginx on FreeBSD 11.1
Nginx is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server, originally written by Igor Sysoev. According to Netcraft, nginx served or proxied 25.92% busiest sites in February 2018. Here are some of the success stories: Dropbox, Netflix, WordPress.com,FastMail.FM. Some features of the Nginx Web server include Serving static and index files, autoindexing, open file descriptor cache and Accelerated reverse proxying with caching, load balancing and fault tolerance.
Nginx comes into forms,the open source edition and the enterprise edition.
In this tutorial we will install the open source version of nginx which is available on most Linux Distributions and FreeBSD as well.
Let first confirm if nginx is available from FreeBSD repository.
Pkg search nginx
You should the following output:
root@server01:~ # pkg search nginx nginx-1.12.2_3,2 Robust and small WWW server nginx-devel-1.13.7_3 Robust and small WWW server nginx-full-1.12.2_3,2 Robust and small WWW server (full package) nginx-lite-1.12.2_3,2 Robust and small WWW server (lite package) nginx-naxsi-1.12.2_3,2 Robust and small WWW server (plus NAXSI) p5-Nginx-ReadBody-0.07_1 Nginx embeded perl module to read and evaluate a request body p5-Nginx-Simple-0.07_1 Perl 5 module for easy to use interface for Nginx Perl Module p5-Test-Nginx-0.26 Testing modules for Nginx C module development
From the output above,nginx version 1.12 is available and we can easily install with the command below.
pkg install nginx
The following output will be shown:
root@server01:~ # pkg install nginx Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 2 package(s) will be affected (of 0 checked): New packages to be INSTALLED: nginx: 1.12.2_3,2 pcre: 8.40_1 Number of packages to be installed: 2 The process will require 7 MiB more space. 1 MiB to be downloaded. Proceed with this action? [y/N]:
We then press y to install nginx.
To confirm if nginx is successfully installed,use the command below.
This should print the version of nginx installed.You should see something similar to the following.
root@server01:~ # nginx -v nginx version: nginx/1.12.2
After we are certain nginx is installed,lets check if its running
service nginx onestatus
Output should be simmilar to the below:
root@server01:~ # service nginx onestatus nginx is not running.
Note:In checking the status of nginx, we used onestatus instead of status.This is because for status to be used,we need to set nginx_enable to YES in /etc/rc.conf. Run the command below to confirm.
root@server01:~ # service nginx status Cannot 'status' nginx. Set nginx_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'.
Lets set nginx_enable to YES in the /etc/rc.conf file by running the command:
echo "nginx_enable="YES"" >> /etc/rc.conf
Lets confirm by running service nginx status again
root@server01:~ # service nginx status nginx is not running.
Error is gone and we are set to go.
Now lets then start nginx by running the command:
root@server01:~ # service nginx start 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.
root@server01:~ # service nginx status nginx is running as pid 6405.
Now nginx is running with default configurations.
Lets test this by opening the default web page on our browser.
You should see something similar to the below:
Nginx is successfully installed and running.
In part 2 of this this tutorial,we will look into the location of the configuration files and how we can customize nginx to meet our needs be it in production or test environment.
All comments and suggestions are welcome and will be appreciated.
Thanks for reading.