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 :?
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
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)
We can check our nginx version with -v option of command
Now we need to add http service to our linux firewall with firewall-cmd --add-service=http command
We can control it with firewall-cmd --list-all command
After that we are able to use nginx. Lets start nginx with systemctl command
We can use systemctl status for checking “status”
So as we can see it is running. Now we need to use hostname -I command to display network address of host.
Then we can use that address on our browser to connect server
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 :
Line 33-36 offers us that under conf.d folder we can store our own configurations.
领英推荐
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)
At the same time we will need index.html file. Lets create it and add “my name is Orkhan Safarov” string to it.
Then we need to create configuration file inside /etc/nginx/conf.d directory
Then we need to add following code block to it :
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
After we need to use systemctl reload to? ask all units listed on the command line to reload their configuration.
Then we need to check that systemctl status for nginx and confirm that it is running properly
Thats it now all remains it to check browser with same ip address :
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?