Nginx has two branches: mainline version and stable version. It is recommended that in general you deploy the NGINX mainline branch at all times. This article will show you how to install the mainline branch on ubuntu server.
Install Nginx Mainline Branch on Ubuntu
First, remove your existing Nginx Installation.
sudo apt-get remove nginx nginx-common nginx-full nginx-core
Next install Nginx PGP key on your system.
wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key
After that edit /etc/apt/sources.list file.
sudo vi /etc/apt/sources.list
Add the following two lines at the end of the file. Replace codename with your specific ubuntu codename, such as trusty for ubuntu 14.04.
deb http://nginx.org/packages/mainline/ubuntu/ codename nginx deb-src http://nginx.org/packages/mainline/ubuntu/ codename nginx
During the installation process, Nginx will automatically install new configuration files. So before the installation you should backup the main config file /etc/nginx/nginx.conf. Your server block file /etc/nginx/sites-available/yourdomain.com will be changed, so you don’t have to back up that file.
sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old
Now update local package index and install Nginx mainline branch.
sudo apt-get update && sudo apt-get install nginx
Once the installation is completed, check your nginx version.
[email protected]:~$ nginx -v nginx version: nginx/1.9.8
Configure Your New Nginx Server
By default, the new config file /etc/nginx/nginx.conf set the user as nginx.
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;
Make sure your PHP pool file www.conf has the same user as defined in nginx.conf, or your website will be broken. And also add the following two lines in nginx.conf file.
include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*;
Then reload your nginx configuration.
sudo service nginx reload
Now your website should be running as usual. If you don’t want to use the new config file, just copy the old configurations to nginx.conf.