You have a DigitalOcean Ubuntu/Debian distribution droplet, or one-click apps packaged with Nginx. By the distro default, the Nginx version is Nginx 1.4 from year 2013/2014.

You are not happy with that and wanted to upgrade it to latest stable like Nginx 1.8.1.


Try to find out your current Nginx version with nginx -v.

If you're on Ubuntu, you can also check your OS version lsb_release -a.

Update the core apt-get update && apt-get upgrade

Backup Nginx configuration files. There are usually in:

  • /etc/nginx/nginx.conf
  • /etc/nginx/conf.d/

Upgrade Nginx

Add the new Nginx stable repository.

add-apt-repository ppa:nginx/stable

Update the new repository and install it.

apt-get update
apt-get upgrade nginx

Configure and test Nginx

It will ask you how would you like to deal with your old configuration files like below.

Configuration file '/etc/nginx/nginx.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N]

Here's an example and simplified version of the new config file looks like below.

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

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


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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php5-fpm.sock;

You have snippets/fastcgi-php.conf now.

Test your config files with service nginx configtest make sure they are OK.

Lastly, do service nginx restart and enjoy a stable version of Nginx in running as your web server.

Bonus: Hiding server token

Go to /etc/nginx/nginx.conf and uncomment the following line.

server_tokens off;

Run curl -I and you see the version number no more.