Nginx is a very lightweight HTTP web server written in C programming language and interactively runs on Unix and Unix like (Linux) operating system. But it also can be configured on Windows. Nginx is the short form of “Engine X”. In this tutorial, we will learn How to Install Nginx web server on CentOS 7 rpm based Linux distribution.
Nginx is a web server but it also works as a load balancer. It is a very flexible web server alternatives to Apache HTTP web server. Nginx creates a reserved proxy server environment on the installed machine. We will use CLI to install Nginx on CentOS.
Install Nginx Web Server on CentOS 7
To install Nginx first of all, login to your server terminal and access as root. Then update the software package manager by running the following command:
$ yum -y update
After updating all the software packages and package manager now we will create a repository file for the Nginx web server under the
/etc/yum.repos.d/ directory as
nginx.repo file. It is a very important phase for pre-installing the Nginx server. Run the following command, it will open a text editor as well as create a new file as
$ nano /etc/yum.repos.d/nginx.repo
Now copy and paste the following code in the text editor that opened in the terminal.
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/rhel/7/$basearch/ gpgcheck=0 enabled=1
Now save the file and exit the editor.
Installing the Nginx Latest Version
To install Nginx latest version from epl repository using yum package manager, run the following commands:
$ sudo yum install epel-release
$ sudo yum install nginx
Manage Nginx Server
If you finish all the above step by step, then congratulations! You have successfully installed the Nginx web server on your CentOS 7 machine. Now we can manage the server in many ways again the same by using the terminal.
Start/Stop/Restart Nginx Server
You can run the following command to start the Nginx server:
$ sudo systemctl start nginx
If you want to stop the server you can run the following command as well:
$ sudo systemctl stop nginx
Run the following command to restart the server immediately without stopping:
$ sudo systemctl restart nginx
Start Nginx on System boot
You will want to keep your server up and running by your best. If you want to start the Nginx server when your system boot then run the following command to activate this feature:
$ sudo systemctl enable nginx
Testing Nginx Web Server on CentOS 7
Now to test your server it is working or not, open your favorite browser and type your configured domain name or IP. If you get following window or something like that, it means your server is up and running:
Congratulations! you have successfully installed Nginx web server.