Nginx: A Beginner's Guide to Installation and Configuration
This Photo Belongs to Mahmud Ridwan

Nginx: A Beginner's Guide to Installation and Configuration

We can describe nginx and its power over apache like this :

Nginx is a web server that processes information between the actual server and browser. Its configuration detects the required files and passes these files to the browser in front. Apache Web server also does this thing same but it gets very slower when comparing with nginx. That’s why most of the web is using nginx. But a question pops up. Do we need a web server ? . The main answer to this question is No. But if you are intending to work multiple servers and multiple users at same time with low delay time then you have to use it.

NginX configuration file knows which server to search for a specific requested file.

This diagram shows the importance of nginx as a web server :?

No alt text provided for this image

To use NginX we need to install it first which is not installed default by most of distros.


I will use centOS 9 for this documentary.


First we need to get the information from our default repository about nginx

No alt text provided for this image

After that we can select our specific stream of it and then install it with yum (we can add -y option for automatic answer popped up questions)

No alt text provided for this image

We can check our nginx version with -v option of command

No alt text provided for this image

Now we need to add http service to our linux firewall with firewall-cmd --add-service=http command

No alt text provided for this image

We can control it with firewall-cmd --list-all command

No alt text provided for this image

After that we are able to use nginx. Lets start nginx with systemctl command

No alt text provided for this image

We can use systemctl status for checking “status”

No alt text provided for this image

So as we can see it is running. Now we need to use hostname -I command to display network address of host.

No alt text provided for this image

Then we can use that address on our browser to connect server

No alt text provided for this image

As you can see we will see the default html of nginx http server.

Normally it shows that our nginx server is running with everything ok. But we are planning to use custom html, then we need to use its configuration file.


Let’s first check how it shows this html file so that we can get better understanding

We can access config file by this path : /etc/nginx/nginx.conf

Let’s see what? important things it offers :

No alt text provided for this image

Line 33-36 offers us that under conf.d folder we can store our own configurations.

No alt text provided for this image

At line 38-54 shows the default configuration file which will be set if there is no configuration file under /etc/nginx/conf.d directory

For beginner friendly project, these 2 informations are essential for us.

Lets create our folder which will store our html file. (we will reference from default directory)

No alt text provided for this image

At the same time we will need index.html file. Lets create it and add “my name is Orkhan Safarov” string to it.

No alt text provided for this image

Then we need to create configuration file inside /etc/nginx/conf.d directory

No alt text provided for this image

Then we need to add following code block to it :

No alt text provided for this image

In this text :?


Server { }? : defines a virtual server that can respond to HTTP requests

Listen : specifies the IP address and port number where Nginx should listen for incoming connections.

Index : specifies the default file name to use when a client requests the root directory of the website

root : specifies the directory where Nginx should look for the files to serve


Normally this configuration file can be enhanced for more enterprise websites. But for now we are keeping it simple for one html page


Then we need to check the nginx syntax with -t option of command

No alt text provided for this image

After we need to use systemctl reload to? ask all units listed on the command line to reload their configuration.

No alt text provided for this image

Then we need to check that systemctl status for nginx and confirm that it is running properly

No alt text provided for this image

Thats it now all remains it to check browser with same ip address :

No alt text provided for this image

As you can see we now able to see our index.html rather than default html.


Written by : Orkhan safarov?

Email : [email protected]

Youtube : https://www.youtube.com/@Orkhan-Safarov?


要查看或添加评论,请登录

Orkhan Safarov的更多文章

  • Docker imperative commands

    Docker imperative commands

    In my previous article I introduced Docker for beginners In this guide, we'll dive into the heart of Docker's…

  • Docker for beginners

    Docker for beginners

    What is Docker ? Docker is a platform for developing, shipping, and running applications. It provides a way to package…

  • A Comprehensive Guide to yum config-manager Utility in CentOS/RHEL Distros

    A Comprehensive Guide to yum config-manager Utility in CentOS/RHEL Distros

    For system administrators and Linux enthusiasts, managing software repositories is an essential task. The yum…

社区洞察

其他会员也浏览了