HostUp

How to Install & Configure Latest Nginx Mainline Version on Ubuntu 16.04 / 18.04

Why am I writing this tutorial?

Hi there again! I choose to write this tutorial because I have gotten very frustrated looking around for tutorials that actually work for the latest version of Nginx. All other guides only works for Nginx 1.12 and below, even though the current version is 1.15.8. This is simply dumb and I hope that with this you do not have to look around for hours upon end without any progress whatsoever!

Install Nginx

To install the current version of Nginx, simply follow the documentation on its offical website seen here or do the following commands:

sudo apt install curl gnupg2 ca-certificates lsb-release
echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \     | sudo tee /etc/apt/sources.list.d/nginx.list
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - 

Now that we have downloaded & verified its authnicity lets install it!

sudo apt update
sudo apt install nginx

Useful Commands

That’s it! You have now installed the latest release of Nginx. You should now start it and make it start on reboot.sudo systemctl start nginx.service
sudo systemctl enable nginx.service

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

To restart or stop nginx:

sudo systemctl stop nginx.service
sudo systemctl restart nginx.service

Setup Your Website

You should now verify that nginx has started and is correctly installed by visiting it. Http://YourServerIp. If everything is correctly setup you should see something like this:

Image result for welcome to nginx
The default index page for nginx.

Your website configuration is located at/etc/nginx/conf.d/default.conf
Your website HTML files are located at/usr/share/nginx/html

Now what?

Well now you can upload your own files or install wordpress as shown here

If you should happen to want to install PHP you need to configure Nginx a little bit more. Otherwise it can cause permission problems later down the road, like returning permission denied errors.

Add nginx to www-data group

sudo usermod -a -G www-data nginx

Change owner of directory to www-data

sudo chown -R www-data /usr/share/nginx/html

David

Want Ubuntu tutorials that actually work? Then you have found the right person

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
0 Comment authors
Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
trackback

[…] web server to run the WordPress software. To do this is quite simple. Just follow this tutorial on How to Install Nginx. There is a few basic things that you need to know if you have never done this before. The $ […]

trackback

[…] there again! If you are like me and want to use the friendly URLs option with Nginx on WHMCS, but noticed that it does not work, then you have come to the right […]