Wednesday, September 7, 2022

How to Install and Configure Nginx proxy pass on centos



Nginx is a web server which can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004.

This tutorial will teach you how to install and start Nginx on your CentOS server.

Step-1 Add Nginx Repository.

$sudo yum install epel-release

Step-2 Install Nginx.

$sudo yum install nginx

Step-3 Start Nginx service.

After installation Nginx, use the below commands to start and enable the Nginx service.

$sudo systemctl start nginx

$sudo systemctl enable nginx

Check the status of the Nginx service with the following command.

$sudo systemctl status nginx

The output should look something like this.

nginx.service - The nginx HTTP and reverse proxy server

  Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)

  Active: active (running) since Mon 2018-03-12 16:12:48 UTC; 2s ago

  Process: 1677 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)

  Process: 1675 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)

  Process: 1673 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Main PID: 1680 (nginx)

  CGroup: /system.slice/nginx.service

          ├─1680 nginx: master process /usr/sbin/nginx

          └─1681 nginx: worker process


If you are running a firewall, allow HTTP “80” and HTTPS “443” traffic, run the below commands.

$sudo firewall-cmd --permanent --zone=public --add-service=http 

$sudo firewall-cmd --permanent --zone=public --add-service=https

$sudo firewall-cmd --reload

Step-4 Verify installation.

To verifying the Nginx installation open your browser and type http://YOUR_SERVER_IP 

You will see the default Nginx welcome page as shown in the image below.


Configure the reverse proxy Nginx.

Open Nginx configuration file in your choice editor.

$sudo vim /etc/nginx/nginx.conf

Configure your setting as an example given below and save & exit.

server {

      listen 443 ssl http2;

      server_name  172.16.x.x #Domain name or IP

location / {

       proxy_pass http://bizdirect-coupons-async.172.16.1.0.nip.io; #Where you want to redirect your request localy. 

             proxy_http_version 1.1;

        }

}

server {

      listen 80;

      server_name  172.16.x.x; # Put Domain name or IP here.

location / {

       proxy_pass http://bizdirect-coupons-async172.16.1.0.nip.io; #Where you want to redirect your request localy.

             proxy_http_version 1.1;

        }

}

Restart Nginx service.

$sudo systemctl restart nginx

Conclusion.

Congratulations, you have successfully installed Nginx on your CentOS server.

You’re now ready to start deploying your applications and use Nginx as a web or proxy server.

No comments:

Post a Comment

What is DevOps? DevOps Kya hai?

DevOps is not a tool or a software. DevOps simply is a hassle free process to implement, develop and deliver the product to client. It'...