INSTALL AND CONFIGURE NGINX WEB SERVER

INSTALL AND CONFIGURE NGINX WEB SERVER


Nginx is a free powerful lightweight and open-source HTTP web server application. It is written in C programming language, which can be used in Linux and its other Linux distributions and can also be used in Windows Server. It can also be used as a reverse proxy and load balancer. It helps you manage your web server with high performance, power, stability and availability with rich features. Nginx is an alternative web server to Apache web server, it accounts for about 33% of web servers used all over the world. It gives high performance by utilizing the working resources of the server. Through this article, we will learn how to install and configure the Nginx server in Centos and Linux servers.

Install Extra Packages for Enterprise Linux

  • You cannot find packages of Nginx in the standard repository of Centos so you have to install the EPEL repository in the system. With the help of EPEL, you can install numerous open-source packages in your system. You can use the following command to install the EPEL repository.
sudo yum install -y epel-release
  • Before installing the package of the Nginx web server in the system, update the system with the help of the following command. If you set the Y in the command, you will not have to press the Y key again and again.
#dnf update  -y 

Install Nginx Web Server

  • After adding the EPEL repository and successfully updating the system, you can install the package of Nginx in the system. You can use the following command to install the Nginx Package in the system.
Install Nginx Package in centos

Verify the Nginx Package

  • With the help of the following command, you can check the package version of Nginx installed in the system.

CONFIGURATION OF NGINX.

  • open Nginx configuration with the help of any text editor and go to Near Line number 41 and put your hostname.
[root@centos8 ~]# vim /etc/nginx/nginx.conf                                                                                                                                      .                                                                                                                                                                                                          .                                         { go to Near Line Number 41}                                                                                                                                    server_name  www.simitech.in             {Change Your Server Name  }                                                                                                                                                                                                                                                                   
  • Change your Server Name
Configure Of Nginx Server In Centos 8

start and check the Nginx Service

  • After successfully configuring the Nginx server, you have to start the services. You can use the following command to check and start the service.
#systemctl start nginx                        
  • If you want to start the Nginx service automatically when the server is restarted, you can use the following command.
#systemctl enable --now nginx
Start, Enable And Check Service In Nginx Http Web Server in centos

Firewall setting open port 80 and 443

  • If the firewall service is running in your system and you want to access the Nginx web server through the firewall, then you have to open the system’s post numbers 80 and 443 with the command given below.
firewall service is running , allow HTTP service

Check Nginx Defaults Web page

  • After all the configuration of the Nginx server is successfully done, you can test it with the help of any browser of the system to view its default web page. For example, you can see the screen below.
Default page of Nginx http web server

VIRTUAL HOSTING IN NGINX:

  • now will learn about how you can test virtual hosting in Nginx Server. Before looking at virtual hosting, let us know what is virtual hosting. Virtual hosting is a technique with which you can host many servers in a single system. You can run a lot of servers using just one IP Or domain name.
  • for virtual hosting in Nginx, first, create a file named virtual.host.conf under /etc/nginx/conf.d/ location you can see in the step below.
# vim  /etc/nginx/conf.d/ virtual.host.conf
 Create virtual.host.conf  file In Nginx  HTTP Web Server
  • Create Directory simitech.host under /usr/share/nginx/ and Restart Nginx Services
create Directory Under  /usr/share/nginx/ in centos
  • Create Test page index.html under /usr/share/nginx/simitech.host/ location and write simple HTML code for test Nginx Virtual Hosting as below see.
write simple html code for  Testing
of Index Page in Nginx server
  • open system web browser and put simitech.host in the URL now the Nginx virtual host test page is working.
 nginx virtual host test page Output Through Browser

Configure Nginx to use php Scripts

  • first Install the latest PHP 7. x in the Nginx server with the help of the below command.

[root@centos ~] # dnf module install php:7.2 -y

Install Php 7.2 In Inginx Http Web Server
  • when the latest PHP language is installed in the system you can check the PHP Install Version:
check PHP Version
  • After successfully Install PHP in the system, now you can restart Nginx services and Create one PHPInfo file under/usr/share/nginx/html/info.php
[root@centos8 ~]# systemctl restart nginx                                                                                                                                                                                          root@centos8 ~] # echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/info.php
  • Restart and check the Nginx services
  • Now access the phpinfo.php page from your system web Browser.
Check PHP Installed Modules
  • php configuration done, now you can use the PHP script

Conclusion

In this article, we have tried to learn in detail about installing Nginx on Centos/Linux and hope that now you will have cleared many doubts related to installing Nginx on Centos. If you have any doubts about this article, you can ask your questions through comments or mail. Your questions will help to make our website better. You can also check these Articles Best External Hard disk

Rate this post