Day 16/100 of DevOps
Day 16: Install and Configure Nginx as an LBR
Task: a. Install nginx on LBR (load balancer) server.
b. Configure load-balancing with the an http context making use of all App Servers. Ensure that you update only the main Nginx configuration file located at /etc/nginx/nginx.conf.
c. Make sure you do not update the apache port that is already defined in the apache configuration on all app servers, also make sure apache service is up and running on all app servers.
d. Once done, you can access the website using StaticApp button on the top bar.
Click on the
StaticAppand check the result.it should be showing error

SSH to the Load Balancer

Update the packages and install nginx
sudo yum update -ysudo yum install nginx -y

Start, enable and check the status of the
nginxservicesudo systemctl start nginxsudo systemctl enable nginxsudo systemctl status nginx
Validate the port on which apache service is running on all the server
Open another terminal and login to
stapp01SSH into the app-server.
thor@jumphost ~$ ssh tony@stapp01Let's get the port details of the apache service (httpd).
[tony@stapp01 ~]$ sudo ss -tulp | grep httpd
As you can observe, the apache service is running on port 8087 in this scenario. Verify if it’s running on the same port for all the app-servers.
Edit the default config file to point the load balancing to run on those 3 app-servers.
vi /etc/nginx/nginx.confAdd below in the
httpblock:http { # … (keep existing directives that Nginx ships with) upstream myapp1 { #-------> These server stapp01:8087; #-------> lines server stapp02:8087; #-------> are server stapp03:8087; #-------> added # default method is round_robin } server { listen 80 default_server; server_name ; location / { #---> Also this line proxypasshttp://myapp1; #---> and this line } } }

Let me explain, what exactly are we adding in the configuration file.
- Thehttp {}block is the main context for HTTP traffic in Nginx.
-upstream app_servers→ Defines a pool of backend servers for load balancing.
-server→ Defines an Nginx virtual server that listens for incoming client requests.
-location /→ Matches all requests to the root path (/) or anything under it.
-proxy_set_header→ preserves original client info and protocol.Validate Nginx Config & Reload
sudo nginx -t
sudo systemctl reload nginx
Now click on
StaticAppand validate