Install and configure Nginx on FreeBSD

I will show you in this tutorial how to install Nginx web server and configure it on FreeBSD system.

Nginx installation

To install nginx enter as root the following commands in terminal :
pkg update
then
pkg install nginx

root@freebsdsrv:~ # 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.18.0_45,2
    pcre: 8.44

Number of packages to be installed: 2

The process will require 8 MiB more space.
2 MiB to be downloaded.

Proceed with this action? [y/N]:


Enter y then hit Enter.

Nginx Configuration

When is done with nginx installation, you should now enable it by setting nginx_enable to YES in /etc/rc.conf with this command :
nano /etc/rc.conf

then input to bottom (end of file)
nginx_enable="YES"

Now it’s time to start nginx with :
service nginx start

root@freebsdsrv:~ # 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.


To check status of nginx enter :
service nginx status

root@freebsdsrv:~ # service nginx status
nginx is running as pid 50574.


To restart nginx enter :
service nginx restart

To stop nginx enter :
service nginx stop

Now to test nginx is working, first make sure there is no firewall restricting access to 80 port (http), then enter the ip address of your nginx machine in Web browser for example :
http://192.168.8.31/

You should see page like this :
 

To set your domain name (for example : www.mywebsite.com) to nginx, then edit nginx configuration file :
nano /usr/local/etc/nginx/nginx.conf

Go to :


    server {
        listen       80;
        server_name  localhost;


Then add www.mywebsite.com after localhost, like that :

    server {
        listen       80;
        server_name  localhost www.mywebsite.com;
 

Then save configuration file with CTRL+S and exit with CTRL+X

Now restart nginx to load your new configurations with :
service nginx restart

root@freebsdsrv:~ # service nginx restart
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
Stopping nginx.
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.



Popular posts from this blog

Linux Mint : 26 Reasons Why I Use It And You Should Too

How to create an AppImage to bundle your software

SEO Services Primelis Company: Rank Fast in Google