Introduction
Nginx is a free and open-source, high performance web server software popular for its stability, simplicity in configuration and low resource consumption. Here also, the user needs to have root privileges for execution of commands. Please refer to this tutorial to do the initial server setup for CentOS 7.
For the installation of nginx using yum command, you will have to include the EPEL i.e., Extra Packages for Enterprise Linux. Yum as a package manager will not have the latest version of nginx in its default repository. So, you need to install EPEL in order to ensure that nginx on CentOS is up to date.
Open up your terminal and run the command for installing EPEL.
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Installation of Nginx
Open up the terminal and just run the command to install nginx.
sudo yum install nginx
Once you enter yes to the system prompt, nginx will get installed on your virtual private server.
Starting Nginx
To start nginx, you need to type in the following command. Nginx does not start automatically.
sudo systemctl start nginx.service
Now, verify the nginx installation on your VPS by navigating to your IP address in browser. Get your server’s IP address by running:
http://server_IP_OR_domain_name/
You can use the following command to get the IP of your server:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
The welcome screen of the CentOS 7 Nginx will be displayed. It should look like this:
If you want the Nginx to start at the time of system boot, you can do that with the following command:
sudo servicectl enable nginx.service
You have successfully installed Nginx!