Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Nginx for Load Balancing

Tech May 12 4

Setting Up the Nginx Environment

This setup uses CentOS 7 with properly configured yum repositories. For those needing repository configuration, the Alibaba Cloud mirror site provides necessary resources.

Begin by creating and navigating to the Nginx directory:

mkdir -p /soft/nginx
cd /soft/nginx

Download the Nginx source package using wget:

wget https://nginx.org/download/nginx-1.21.6.tar.gz

Extract the downloaded archive:

tar -xvzf nginx-1.21.6.tar.gz

Install required dependencies for building Nginx:

yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

To prevent potential compilation errors, also run:

yum -y install gcc gcc-c++ autoconf automake make

Navigate into the extracted directory and configure the build:

cd nginx-1.21.6
./configure --prefix=/soft/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module

Compile and install Nginx:

make && make install

Start the Nginx service after installation completes.

Configuring Load Balancing

Load balancing distributes incoming network requests across multiple backend servers to ensure no single server becomes overwhelmed. In Nginx, this is achieved through upstream blocks.

Define upstream servers in the Nginx configuration file:

upstream backend_servers {
    server 192.168.1.10:8080;
    server 192.168.1.11:8080;
    server 192.168.1.12:8080;
}

server {
    listen 80;
    location / {
        proxy_pass http://backend_servers;
    }
}

This configuration creates a load-balanced group named backend_servers containing three application instances. The proxy_pass directive forwards client requests to this group, allowing Nginx to automatically distribute traffic among the defined servers.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.