Install latest NGiNX on CentOS 7


In this short tutorial we will learn how to install latest NGiNX version on CentOS 7. In an era of containers and all fancy technologies we have to admit that from time to time we need to look and even go back to the basics and install ourselves, manually services like NGiNX for example. NGiNX is a great web server software being able to perform very well as reverse proxy, load balancer and even as ingress router for container technologies. Indeed the free version of NGiNX may not have all capabilities as the commercial one but still plenty of nice features left there to use for any of our future projects. There is no secret that NGiNX has been built for speed and config syntax simplicity and we think is doing a brilliant job covering these two major points successfully and we could even dare to say that is extremely powerful. We would not try explain in this tutorial any of NGiNX features but we will definitely guide you, step by step, how to setup lates NGiNX version on a CentOS 7 system using the official NGiNX repository and yum package manager that come by default with CentOS.

Table of contents

Create nginx.repo file
Install latest NGiNX version
Check NGiNX installation
Enable and start NGiNX service
Test NGiNX locally

Create nginx.repo file

Our very first step in setting up latest NGiNX version begins with creating a repository file for NGiNX packages, now using vi editor we will create a new repository file called nginx.repo that will be later used by yum package manager, lets create this file by running the next command like shown in the example below:

$ vi /etc/yum.repos.d/nginx.repo

No worries, you are free to use any text editors that you are comfortable with but in this tutorial we will use vi editor.

Now all we have to do is just to add the lines below inside our newly created nginx.repo file, these lines will instruct yum where to get NGiNX from, so please just copy and paste the next lines:

name=nginx repo

Save and close the file using :x command within vi editor if you are using this editor, that is all in terms of repository configuration, we can now move forward to our next step.

Install latest NGiNX version

In this particular step we will make use of yum package manager, utility software that comes by default with CentOS and will facilitate our NGiNX installation. Using yum command followed by -y argument basically we will instruct yum to execute the install process without any user confirmation input:

$ yum -y install nginx

NGiNX installation process should take no more than a few seconds including all its associated dependencies. Once this step is successfully executed and completed we may say that we have managed to install NGiNX on CentOS 7.

Check NGiNX installation

Lets have a closer look to see if NGiNX has been properly installed by checking its status, so lets run the next command on our terminal window:

$ systemctl status nginx

A successful output should look similar to this one listed below:

● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Even though the service is flagged as inactive (dead) we can now confirm that NGiNX is present onto our system but is not enabled and started yet.

Enable and start NGiNX service

Before starting the service lets make sure that this is enabled to start automatically during system reboots:

$ systemctl enable nginx

We should get this output on our terminal window confirming that NGiNX has been successfully enabled to start automatically:

Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/nginx.service.


To start NGiNX service is easy and like any other service on CentOS 7 we may have to use systemctl like shown in the example below:

$ systemctl start nginx


Once again lets perform a quick check to see if NGiNX is now really running on our CentOS 7 system:

$ systemctl status nginx

If everything went fine and no errors were encountered then we should be able to see a similar output on our terminal window:

● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-05-14 10:20:55 UTC; 55s ago
  Process: 4428 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 4429 (nginx)
   CGroup: /system.slice/nginx.service
           ├─4429 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─4430 nginx: worker process

May 14 10:20:55 mny-aws-euw1-pvm-app001 systemd[1]: Starting nginx - high performance web server...
May 14 10:20:55 mny-aws-euw1-pvm-app001 systemd[1]: PID file /var/run/ not readable (yet?) after start.
May 14 10:20:55 mny-aws-euw1-pvm-app001 systemd[1]: Started nginx - high performance web server.

Test NGiNX locally

Knowing now that NGiNX has been installed, started and even enabled lets take a quick test locally using but before that lets make sure that we have curl utility installed in order to perform this check:

$ yum install -y curl

Using curl utility lets try to get a header response from NGiNX using its default configuration:

$ curl -I localhost

A 200 OK response code means that our local request is successful and NGiNX works as expected:

HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Tue, 14 May 2019 10:22:16 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 23 Apr 2019 14:36:26 GMT
Connection: keep-alive
ETag: "5cbf22ea-264"
Accept-Ranges: bytes

That is it, our short tutorial ends here, we have learnt in just a few steps how to install latest NGiNX version, how to start and enable the service and even how to perform a quick test.


No video posted for this page.


No screenshots posted for this page.

Source code

No code posted for this page.

About this page

Install latest NGiNX on CentOS 7

Share this page

If you found this page useful please share it with your friends or colleagues.