How To Install Nginx Web Server On CentOS

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or a reverse proxy.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. So today I’m going to show you how to setup Nginx webserver on CentOS 6 or 7. In this tutorial we will learn how to install and configuration of Nginx web server on your CentOS server.

Install Nginx Using Yum Command On CentOS

Step 1. To install, first you must add the Webtatic yum repository information corresponding to your CentOS/RHEL version to yum:

CentOS/RHEL 7.x:

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

CentOS/RHEL 6.x:

 rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Step 2. Install nginx package and dependencies using the below command :

 yum install nginx16

Starting and stopping the server

To start the Nginx server, issue the following command:

 service nginx start

Top stop the Nginx server, issue the following command:

 service nginx stop

Configuration files/folders

  • The main configuration file for Nginx is /etc/nginx/nginx.conf
  • Virtual hosts are defined in /etc/nginx/sites-available/default
  • PHP will be configured in /etc/php5/fpm/php.ini

Before you close that terminal window, it’s necessary to set the Nginx service to start at boot. Just issue the following command:

 chkconfig nginx on

Navigating to your Server’s IP address (assuming you have no other server listening on port 80), you will be greeted with the standard welcome page:

nginx-default

The steps above should produce a running Nginx which serves the Nginx default pages on port 80. We’ll start working through various configurations and optimizations to round out the series. Enjoy your new web server!

Click here to learn How To Install Nginx Web Server on Ubuntu

Leave a Reply