Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of using nginx to set load balance in Linux

Shulou Source: shulou.com Published: 2022-06-02 04:33:07 09月14日 Update

This article mainly introduces the method of using nginx to set load balance in Linux. It is very detailed and has a certain reference value. Friends who are interested must read it!

precondition

You must have root access or sudo access. Use permissions to connect to your server console. Configure your site on the back-end server.

Step 1: install the nginx server

First, log in to your server using ssh access, where Windows users can use an alternative to putty or ssh. Now install nginx using the Linux package manager. The nginx package is available under the default yum and apt repositories.

Use Apt-get:

$sudo apt-get install nginx

Use Yum:

$sudo yum install nginx

Use DNF:

$sudo dnf install nginx

Step 2: set up a virtual host

Let's create a nginx virtual host profile for the domain. The following is the minimum settings profile.

/ etc/nginx/conf.d/www.example.com.conf

Upstream remote_servers {server remote1.example.com; server remote2.example.com; server remote3.example.com;} server {listen 80; server_name example.com www.example.com; location / {proxy_pass http://remote_servers;}}

Step 3: other useful instructions

You can also use some more useful settings to customize and optimize the load balancer using nginx. For example, set, weight, and ip hashes (hashes), as configured below.

Weight

Upstream remote_servers {server remote1.example.com weight=1; server remote2.example.com weight=2; server remote3.example.com weight=4;}

IP Hash

Upstream remote_servers {ip_hash; server remote1.example.com; server remote2.example.com; server remote3.example.com down;}

Step 4: restart the nginx service

After all the changes have been made, restart the nginx service using the following command.

The above $sudo systemctl restart nginx.service is all about the method of setting load balancing using nginx in Linux. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Services servers steps configuration methods permissions hosts content files useful virtual hosts minimum equilibrium value prerequisites interests commands boys buddies instructions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB Apple MySQL Xiaomi