Nginx Installation in CentOS.

Nginx setup in CentOS 7


Nginx is another alternative to Apache HTTP server and gained popularity because of its lightweight nature and high performance.


You need to be a user with root privileges.

1) Update your EPEL release packages to the latest stable version.

sudo yum update -y

2) make sure you do not have Nginx installed already by running the version command.

nginx -v

if there’s no output from above command, then proceed. if not you can remove by below steps:

a) Stop the nginx service

sudo systemctl stop nginx

b) remove all nginx packages.

yum remove nginx -y

3) install nginx package

sudo yum install nginx

use : -y for silent installation.

4) verify if your nginx installation is successful by checking the version.

 sudo nginx -v

5) Change the ownership of /etc/nginx from “root” to user “nginx”

sudo chown -R nginx:nginx nginx

6) start the nginx service

sudo systemctl start nginx

7) if you want your nginx to be started on system boot, mark it for a default start

sudo systemctl enable nginx

8) check the status of nginx daemon if everything is alright.

sudo systemctl enable nginx

9) you can confirm if your nginx is listening by loopback as below

curl -I

10) if you want to server your own pages/applications, default nginx root directory is /usr/share/nginx/html

you can customize the behavior of niginx by editing the default server block config file /etc/nginx/conf.d/default.conf

Note that : you can create more server blocks by adding *.conf files in this directory which will be parsed and loaded by nginx daemon.

11) /etc/nginx/nginx.conf is the key crucial file where you can apply more settings like nginx process ownerships, worker threads to be spawned by nginx threads and
the data directories.

I have put all the above steps in a single unix script to make our installation smooth and can be run as many times it is necessary in same or multiple servers.

Written by Ramesh Metta

Previous Article