Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Nginx reverse proxy load balance in LNMP Architecture

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to configure Nginx reverse proxy load balancing in LNMP architecture. It is very detailed and has a certain reference value. Interested friends must read it!

1. Introduction to the configuration environment

System environment:

[root@centos6 conf] # cat / etc/redhat-release

CentOS release 6.5 (Final)

[root@centos6 conf] # uname-r

2.6.32-431.el6.x86_64

Nginx version:

[root@centos6 conf] # / application/nginx/sbin/nginx-v

Nginx version: nginx/1.10.1

Configure two virtual hosts for subsequent testing

2. Overall logic diagram

Note: when the user accesses, in fact, the address provided by the load balancer is accessed, and then it is forwarded to the backend server according to the corresponding rules

3. Configuration process

[root@centos6 conf] # vi nginx.conf

Worker_processes 1

Events {

Worker_connections 1024

}

Http {

Include mime.types

Default_type application/octet-stream

Sendfile on

Keepalive_timeout 65

Include / application/nginx/conf/extra/upstream01.conf

}

Just add the above configuration.

Next, configure upstream01.conf.

[root@centos6 extra] # vi upstream01.conf

# config to nginx

Upstream test_servers {# defines the host pool

Server 172.16.1.235 8081 weight=5; # polling by weight

Server 172.16.1.235:8080 weight=5

Server 172.16.1.235:80 weight=15

}

Server {

Listen 80

Server_name www.mingonge.com

Location / {

Proxy_pass http://test_servers; # forwards snooping requests to this virtual host pool

}

}

For more information about the upstream module, please refer to the official documentation

Http://nginx.org/en/docs/http/ngx_http_upstream_module.html

4. Restart the service and test

Restart the nginx service

[root@centos6 extra] # / application/nginx/sbin/nginx-t

Nginx: the configuration file / application/nginx-1.10.1/conf/nginx.conf syntax is ok

Nginx: configuration file / application/nginx-1.10.1/conf/nginx.conf test is successful

[root@centos6 extra] # / application/nginx/sbin/nginx-s reload

Linux local client test

[root@centos6 extra] # curl http://172.16.1.235

Welcont to mingongge's blog stie

[root@centos6 extra] # curl http://172.16.1.235

Welcont to mingongge's bbs stie

[root@centos6 extra] # curl http://172.16.1.235

Welcont to mingongge's blog stie

The user client tests with the domain name

The local client needs to resolve the domain name correctly, www.mingongge.com- > 172.16.1.235

Judging from the above test results, it is true that the servers assigned for the two visits are different. In order to test the results, the display content is configured to be different. In the actual production environment, all access display contents are the same. Achieve server downtime without affecting the user's experience.

5. Simulate and test the real environment

Here, we configure the home page content of the two virtual machines to display the same content to simulate the real production environment.

[root@centos6 ~] # echo "welcome to mingongge's web site" > / www/bbs/index.html

[root@centos6 ~] # echo "welcome to mingongge's web site" > / www/blog/index.html

[root@centos6 ~] # cat / www/bbs/index.html

Welcome to mingongge's web site

[root@centos6 ~] # cat / www/blog/index.html

Welcome to mingongge's web site

Linux client test

[root@centos6 ~] # curl http://172.16.1.235

Welcome to mingongge's web site

[root@centos6 ~] # curl http://172.16.1.235

Welcome to mingongge's web site

Stop one of the virtual WEB service functions to simulate the failure. Since we are using the virtual host of nginx itself, we will modify the configuration file and comment out the included configuration file.

# include / application/nginx/conf/extra/vhosts/bbs.conf

If the test uses three servers, you can configure different http services to simulate server downtime (stop WEB services) to test the effect of load balancing closer to the real environment.

[root@centos6 ~] # curl http://www.mingongge.com

Welcome to mingongge's web site

[root@centos6 ~] # curl http://www.mingongge.com

Welcome to mingongge's web site

The client can still access it, indicating that the load balancing function is effective, and when the server downtime occurs, it will not affect the final access of the user.

These are all the contents of the article "how to configure Nginx reverse proxy load balancing in LNMP architecture". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report