Skip to main content

Command Palette

Search for a command to run...

Day 16/100 of DevOps

Day 16: Install and Configure Nginx as an LBR

Published
2 min read

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.

  1. Click on the StaticApp and check the result.

    it should be showing error

  2. SSH to the Load Balancer

  3. Update the packages and install nginx

    sudo yum update -y

    sudo yum install nginx -y

  4. Start, enable and check the status of the nginx service

    sudo systemctl start nginx

    sudo systemctl enable nginx

    sudo systemctl status nginx

  1. Validate the port on which apache service is running on all the server

    Open another terminal and login to stapp01

    SSH into the app-server.

    thor@jumphost ~$ ssh tony@stapp01

    Let'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.

  2. Edit the default config file to point the load balancing to run on those 3 app-servers.

    vi /etc/nginx/nginx.conf

    Add below in the http block:

    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 proxypass http://myapp1; #---> and this line } } }

    Let me explain, what exactly are we adding in the configuration file.
    - The http {} 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.

  3. Validate Nginx Config & Reload

    sudo nginx -t
    sudo systemctl reload nginx

  4. Now click on StaticApp and validate