How to Install Nginx Latest Version on Ubuntu 16.04 and Ubuntu 16.10

In this tutorial, we’re going to learn how to install Nginx latest version on Ubuntu 16.04 and Ubuntu 16.10. At the time of this writing, the latest version of Nginx is 1.11.8, released on December 27th, 2016. You can view changes over previous versions here.

Installing Nginx Latest Version from Official Nginx Repository

Nginx is included in Ubuntu software repository but the version is out-of-date. To install the latest version of Nginx, we will need to add the official Nginx repository.

Open up your sources.list file with a text editor such as nano.

sudo nano /etc/apt/sources.list

In nano text editor, press CTRL+W then CTRL+V to jump to the end of the file. Next, append the following two lines at the end of the file.

Setting the Nginx Process User

The Nginx package from nginx.org repository set nginx as the Nginx process user which can be inferred from the first line of /etc/nginx/nginx.conf file.

user nginx;

However, the default user and group of PHP-FPM process is www-data as can be seen in /etc/php/7.0/fpm/pool.d/www.conf file.

user = www-data
group = www-data

So we need to set www-data as the Nginx process user in /etc/nginx/nginx.conf file.

sudo nano /etc/nginx/nginx.conf

Change

user nginx;

to

user www-data;

Save and close the file. Then reload Nginx.

sudo systemctl reload nginx

Including Server Block Files

By default, only files under /etc/nginx/conf.d/ directory will be included. If you also want to use server block files in sites-enabled directory, then make sure the following lines are added in the http section of nginx.conf file.