How To Install Nginx on Centos 7

September 15, 2016

How To Install Nginx on Centos 7

NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

NGINX is one of a handful of servers written to address the C10K problem. Unlike traditional servers, NGINX doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load. Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from NGINX’s high-performance and small memory footprint. NGINX scales in all directions: from the smallest VPS all the way up to large clusters of servers.

First let’s start by ensuring your system is up-to-date.

Installing and Configuring NGINX in CentOS 7

Nginx is not yet available in CentOS 7 official repositories, so we have to add / install Nginx yum repository by issuing command below:

Start Nginx and add it to automatically start on your system start-up using:

You can verify that Nginx is really running by opening your favorite web browser and entering the URL http://your-server’s-address, if it is installed, then you will see this:

  • Configure Nginx web server

Let’s say you have a domain and you like to use it to host a PHP based web application in /var/www/ like WordPress, Joomla. To set-up Nginx serve requests for, and serve the PHP scripts in /var/www/ you would have to create a server block in /etc/nginx/conf.d/ which would look something like:

Test and re-start Nginx using:

  • Configure IPTables or Firewall

CentOS 7 has a local firewall enabled by default. Proper TCP ports may need to be opened to allow external requests. This will usually be port 80 for normal HTTP traffic:

Congratulation’s! You have successfully installed Nginx.