installation on Ubuntu 16.04 with Nginx

In the previous tutorial we saw how to install and run on Ubuntu with an Apache 2 web server. In this tutorial we will see how to do the same with the Nginx web server.

How to install Nginx on Ubuntu (16.04 LTS +)

Nginx installs very simply with a simple apt-get command.

sudo apt-get update
sudo apt-get install nginx

Accept questions during installation. At the end of the installation, Ubuntu starts the Nginx server. You can easily verify that the server is started using the systemctl status option.

systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy serv
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor pr
   Active: active (running) since lun. 2016-11-21 18:46:50 CET; 2h 46min
  Process: 18423 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry
  Process: 18893 ExecStart=/usr/sbin/nginx -g daemon on; master_process 
  Process: 18890 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master
 Main PID: 18897 (nginx)
   CGroup: /system.slice/nginx.service
           ├─18897 nginx: master process /usr/sbin/nginx -g daemon on; m
           ├─18898 nginx: worker process                           
           ├─18899 nginx: worker process                           
           ├─18900 nginx: worker process                           
           └─18901 nginx: worker process

As we can see, the service is well started, we can move on following the configuration of

Installing on Ubuntu

Recovering sources on GitHub

Let’s start by installing git (unless it is already present on your PC).

sudo apt-get install git

An installation directory is created. It does not matter the location of the directory, install it for example in your user folder or in the Home.

sudo mkdir /home/freeboard_io

We start the recovery of the sources on GitHub

cd /home/freeboard_io
git clone

Creating a symbolic link to /var/www

The files of the website must be located (ideally by convention) in the /var/www. As for Apache, we will simply create a symbolic link that will allow the Nginx server to find the files of the freeboard site.

Note. If you followed the previous tutorial and your Apache configuration is already done, you can skip this step.

sudo -s
cd /var/www
ln -s /home/freeboard_io/freeboard freeboard_io

Configuring Freeboard_io for Nginx

If you go to the directory of Nginx, you will realize that the structure of the folders is very similar to that of Apache.

/etc/nginx# ls
conf.d          koi-utf     nginx.conf    sites-available  ssl
fastcgi.conf    koi-win     proxy_params  sites-enabled    uwsgi_params
fastcgi_params  mime.types  scgi_params   snippets         win-utf

We will therefore create a new configuration (we can also modify the site by default).

sudo nano /etc/nginx/sites-available/

Adapt this configuration to your needs and paste there into the file. Save with CTRL+X and then Y.

server {
      listen 80 default_server;
      listen [::]:80 default_server;

      root /var/www/freeboard_io;
      index index.html index.htm;

      location / {
              try_files $uri $uri/ =404;

Activating the site

Now, activate the site by creating a symbolic link in the sites-enabled folder

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Configuring the Hosts File

As with the Apache configuration, you just have to point the url to the site. To do this, retrieve the ip address of your PC with the ifconfig command and then open the /etc/hosts  file

sudo nano /etc/hosts

Replace the IP address with that of your PC and save       localhost

And now you can access freeboard from your browser using the address

freeboard ubuntu apache2 nginx

Useful commands to manage Nginx

Now that our server is running and the dashboard manager is functional, here are some useful commands to handle Nginx.

To stop the web server

sudo systemctl stop nginx

To start the web server when it is already stopped.

sudo systemctl start nginx

To restart Nginx (this command is equivalent to doing stop and then start).

sudo systemctl restart nginx

To check the configuration before starting (or reloading) the web server.

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload configuration files after a change. Nginx is able to reload the new configuration without cutting existing connections.

sudo systemctl reload nginx

By default, Nginx starts when the (server) computer starts. You can disable this behavior with this command.

sudo systemctl disable nginx

On the contrary, to activate the startup of Nginx at server startup,

sudo systemctl enable nginx

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

We will be happy to hear your thoughts

Leave a Reply

DIY Projects