Nginx web Server installation and configuration on Centos 7/ Redhat 7

NGINX is a high performance web server.It can act as a reverse proxy server for TCP, UDP, HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balance and an HTTP cache. nginx web server installation and configuration on centos 7.

Nginx created in 2002 by Iger Sysoev. Nginx is free open source software.

Features of NGINX:

  • Nginx is secure and very easy to use.
  • It is very easy to configure.
  • It is stable and flexible.
  • Handles static files, index files and auto-indexing
  • Reverse proxy with caching abilities
  • Load balance of nodes
  • SSL/TLS support
  • Fault tolerance
  • Fast CGI (Common Gateway Interface) support
  • IPV6 – compatible
  • Web Sockets and HTTP1.1 upgrade
  • Access control
  • Live stream file compression (FLV and MP4 live streaming)
  • URL rewriting
  • Bandwidth throttling
  • Geo location of IP addresses
  • Low Memory footprint- more than 10000 Concurrent connections with only 2.5 mb of memory for keep-alive Sessions.
  • Limited webDAV
  • Nginx is highly scalable.

NGINX web server installation

Before going to install the nginx package you must need to down, disable apache service.

[root@Techtutorials ~]#systemctl stop httpd.service
[root@Techtutorials ~]#systemctl disable httpd.service

Now install nginx package through yum command

[root@Techtutorials ~]#yum install nginx

Start and enable nginx service

[root@Techtutorials ~]#systemctl start nginx
[root@Techtutorials ~]#systemctl enable nginx

Now able to see an NGINX test page in browser  “http://ipaddress”

You’ll see the default  Nginx web page in browser




Configuration of NGINX:

create a new directory for your site

[root@Techtutorials ~]#mkdir -p /var/www/

create a test file in above directory and edit.

[root@Techtutorials /var/www/]#touch index.html
[root@Techtutorials /var/www/]#vi index.html




<h1>Success! Nginx is properly running on this domain</h1>



Now we need to give ownership of directory and set permissions also.

[root@Techtutorials ~]#chown -R <user>:<user> /var/www
[root@Techtutorials ~]#chmod 755 <user>:<user> /var/www

Create server blocks

[root@Techtutorials ~]#mkdir /etc/nginx/sites-available
[root@Techtutorials ~]#mkdir /etc/nginx/sites-enabled

Edit Nginx’s  configuration file and  goto “end of the http {} block:” add a line declaring an optional directory for additional configuration files:

[root@Techtutorials ~]#vi /etc/nginx/nginx.conf
include /etc/nginx/sites-enabled/*.conf;

server_names_hash_bucket_size 64;


Now create server block file for your domain

[root@Techtutorials ~]#cp -rf /etc/nginx/conf.d/default.conf /etc/nginx/sites_available/
[root@Techtutorials ~]#vi /etc/nginx/sites-available/ 

server {

  listen       80;


  location / {

    root   /var/www/;

    index index.htm index.html;

    try_files $uri $uri/ =404;


  error_page   500 502 503 504  /50x.html;

  location = /50x.html {

    root   html;



Now enable the  new server block files and we can create a symbolic link for each server block  between “sites-available” and “sites-enabled”.
[root@Techtutorials ~]#ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
Restart the nginx service
[root@Techtutorials ~]#systemctl restart nginx.service
That’s it.

Related Article

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

Leave a Reply

Your email address will not be published. Required fields are marked *