Installing Nginx on Ubuntu
Tags: linux, opensource, beginners, nginx
Published: 2021-09-04 23:43:16

Today I'll be showing you how to install Nginx, pronounced Engine X, on Ubuntu..

But first.. what is Nginx?

Because I want to give you the straight forward explanation of what it is..

"NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability"

To read more about it, please visit their website:
https://www.nginx.com/resources/glossary/nginx/


Today I'll be going over how I installed it on my machine!


###  1. Update your System

Before doing anything, I always like to make sure my system is up to date. To do the same, run this command:

![n1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ak14xvhtzhoeqmzy2fzf.png)
 
 
  

### 2. Install Nginx

Simple install it by running the command below:

![n2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98ia2club2cbu42uozb1.png)
 
 

### 3. Create new folder in /var/www

Remember, if we want to create a folder in a specific directory, we will need to move to that directory.

![n3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4q57l2ody4zeeivai5qk.png)
 
While in /var/www, we will create the new folder. Name it whatever you would like, and then, move into that folder, we will need to create a text file in there.

 Here is an example of how to do so:


![n5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3nw7szwhixemaiqolik.png)
 
### 4. Create index.html file

After we move into the new folder we just created. We are going to create the text file.

I prefer to use VIM, but you can honestly use anything you want, like nano.

If you are using VIM, run the command:

*sudo vim index.html*

![n6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5c90x1nv67q3goz8hlj.png)
 
Once you've created the file using *sudo vim index.html*, you're going to need to edit that text file. 

You first have to press 'i' to edit. You can copy what I did below as far as html tags, but you can write whatever you want between the tags.

When done, hit 'esc', type ':wq', and hit enter to quit. Now that file should be saved.



![n7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxaul40wrbg65o5fku22.PNG)
 


### 5. Create the Virtual Host

To create the virtual host, you will need to move to the correct directory first.

See my example on line 5 in the screenshot:

![nn](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83awubap1t4l6a3imyjl.PNG)
 
 
Once we are in that directory, we will create a new file.

*sudo vim (name)*

In my example, I also made the name of my file linuxseb, even though I named my folder that. I suggest creating different names for files and folders so it is less confusing, but it is up to you how you want to go about that! :)

See screenshot below, and copy what I have. 

Also, don't forget!

Be sure for the *server_name* line and the *root* line to replace "linuxwithseb.com" and "linuxseb" with your correct names. 


![n11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnp2n3aen2h9ez77ifpw.png)
 

### 6. Restart Nginx

We are just about done. Go ahead and restart the service by running the command:

*sudo service nginx restart*

### 7. Test it

Once that has been restarted, go to your browser and type localhost:81

and... 

this is what you should get!


![final](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy8l4u02mfnqmcrciayc.PNG)
 

 
If your website is working and it shows up, it means you've successfully installed Nginx :)


### To Conclude

Tutorials like this are for beginners and for practice. Please remember to "stop" Nginx if you're not going to use it. This is just for the sake of security.
 
### To stop it, run this command:

*sudo systemctl stop nginx*

### and to confirm that it has stopped, run this command:

*sudo systemctl status nginx*

### and there you go, you've now learned how to install and configure Nginx on your machine! Thank you all for tuning into my tutorial! More coming in the future :)