NGINX (Engine X) is an powerful web server, Its getting popular very fast due to its fast speed. NGINX is also used as a reverse proxy server. This tutorial will help you to setup NGINX on CentOS/RHEL 7/6 and Fedora systems.

Advertisement

Step 1 – Install Nginx

Nginx packages are available under default repositories. Execute the following command to install latest Nginx available version on your system.

$ yum install nginx    
$ dnf install nginx    #On Fedora 22+ systems 

Step 2 – Nginx Basic Configuration

Do some initial setting before starting nginx. Edit Nginx main configuration file /etc/nginx/nginx.conf and update following values.

$ vim /etc/nginx/nginx.conf

Update following values:

worker_processes  4;   # Number of CPU available in system 
listen  80;  # Port on which nginx will listen 

Step 3 – Start Nginx Service

Use following commands to start Nginx web server and configure Nginx to autostart on system boot.

$ systemctl enable nginx.service
$ systemctl start nginx.service

Now access your server on port 80 with your favorite browser, It will show default Nginx page.

Install Nginx on CentOS

Step 4 – Create VirtualHost in NGINX

After making initial configuration changes to NGINX, let’s start with configuring the first virtual host. Firstly create document root for your application.

$ sudo mkdir -p /var/www/example.com/httpdocs
$ sudo chown -R nginx.nginx /var/www/example.com

Now create an index file with sample text

$ echo "Welcome to NGINX" > /var/www/example.com/httpdocs/index.html

Now create a virtual host configuration file. I just create a copy of default.conf file with name example.com.conf and edit file in the editor.

$ cp /etc/nginx/conf.d/virtual.conf /etc/nginx/conf.d/example.com.conf
$ vim /etc/nginx/conf.d/example.com.conf

Make few changes in the configuration file like below and keep other settings as it is.

server {
    listen       80;
    server_name  example.com;

    location / {
        root   /var/www/example.com/httpdocs;
        index  index.html index.htm;

    }

Finally, restart the NGINX service using the following command

$ sudo systemctl restart nginx.service

Congratulation’s! You have successfully installed Nginx. Read out other articles Install Nginx, MySQL, PHP (LEMP) Stack with PHP-FPM

Share.

2 Comments

  1. gifts for women on

    I think that you could do with some pics to drive the message home a little bit, but other than that, this is great blog. A great read. I will certainly be back.

Leave A Reply

Exit mobile version