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 realize load balancing by configuring http server in nginx

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to configure http server to achieve load balancing in nginx? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

In order to ensure that the two tomcat ports do not conflict, you need to modify the configuration file of one of the tomcat

First of all: under the root (installation) directory of Tomcat, there is a conf folder. Double-click to enter the conf folder, find the server.xml file in it, and open it.

Second: find three areas that need to be modified in the file, as follows:

(1)

It could also be like this:

Wait a minute.

Just change port= "8080" to something else. Such as port= "18080", etc.

(2) change 8009 to another port.

(3) continue to change 8005 to other ports.

Save the server.xml file, restart the Tomcat server, and Tomcat can use port 18080.

In order to distinguish the two tomcat, find the index.jsp under the ROOT under the webapps folder in the tomcat directory, and modify the contents of the tag.

Start tomcat

Find startup.bat in the bin directory of the two tomcat, double-click to start, or open dos in the bin directory and type startup.bat to start.

If there is no flashback, and the window shown below indicates that the startup is successful

Type: localhost:8080,localhost:18080 in the browser address bar, and it will start normally if the following figure is displayed.

Next, configure the nginx.conf file

Worker_processes 1 leads events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; upstream test1 {# down represents a single server temporary load. # weight defaults to the view that the larger the 1.weight, the greater the load weight. # max_fails: the number of failed consent requests defaults to 1. When the maximum number of times is exceeded, the error defined by the proxy_next_upstream module is returned. # fail_timeout: after a max_fails failure. The time to pause. # backup: all other non-backup machines down or request backup machines when they are busy. So this machine will be the least stressed. Server localhost:8080 weight=5; server localhost:18080 weight=10;} server {listen 80; server_name localhost; root Dizuza Root; location / {proxy_pass http://test1; # the name of test here should be the same as that of upstream above}

Then start nginx and access localhost in the browser

This is the answer to the question about how to configure the http server to achieve load balancing in nginx. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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

Internet Technology

Wechat

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

12
Report