https://tinyurl.com/y8fgdzbf

Today I am gonna talk about something I started to learn recently. I have used nginx many times, but didnt have much deeper understanding. So I decided to dig deeper. Luckily I found Hussein Nasser’s Nginx series. I highly recommend you to follow it. Here in this post, I will try to give you a briefer description about nginx and simplest configuration to run and serve our sites. So lets get started.

What is Nginx

Nginx basically has two main features.

  • Web Server
  • Proxy (Layer 7 and Layer 4)

But here we will focus on the most important part of nginx, Proxy. I wont describe what is a proxy and how it works deeply. Simply a proxy is a thing that hides backend to frontend users. This frontend — backend connecting can be done based on many smart decisions. We will cover some in this post.

Install Nginx

Simply follow the given instructions given here and verify your installation working successfully. Check where is your is located. For Ubuntu 20.04, I had it under .

You can use official instructions here. Nginx supports 4 signals commands.

  • reload — reloads configuration file.
  • stop — stops running nginx (fast shutdown)
  • quit — stops nginx (gracefully)
  • reopen — opens log files ( we would need this later)

Creating the simplest nginx web server

First thing first, backup your original file and then only delete the content in original file to start from scratch.

http {server {
listen 8000;
}
} # http blockevents { } # events block

This is the simplest nginx web server running , before restart lets find out what are these different blocks and their purpose in this configuration file.

Here from and blocks considered as main components. Any config file MUST have them. This example, we use nginx as a layer-7 loadbalancer. Thats what’s why we need block. If we want to use nginx as layer-4 LB, it should be .

Inside block, we have our , this part we define our actual nginx server configurations. In this example we are gonna listen. Here nginx will listen to

Next its , this configuration is mainly used to define event-based connections. Simply how worker process should handle connections. This is done automatically. For linux systems its etc. You can read more from here.

Testing

After you enter this configurations to file, save and exit. Open a terminal and run , as described above, this will load our new configuration file to nginx instance. If steps gets an error, it will give you what went wrong similar to below one.

nginx: [emerg] directive “upstream” has no opening “{“ in /etc/nginx/nginx.conf:4

If you have no errors, you can visit and you will see default nginx web page.

So in next time, lets create a layer-7 loadbalancer using nginx.

DevOps who is willing to learn and try new things.