Load balancing server nginx detailed configuration operation

Background review

The company's business is developing too fast. After building a website, one tomcat can handle it. Now I have to use two tomcats. What should I do? To make two tomcats can run together, nginx technology is needed.

How to install? How to configure? How to use it?

The previous article solved the first problem, how to install, please refer to the article "Load Balance Server nginx Detailed Installation Tutorial and Network Deployment" , according to the article's tutorial installation, so far I can see the following interface through the browser now:

Not bad, so how to continue?

To review, what I want to do now.

I now have two tomcats, which deploy an online mall with huge traffic, and the applications deployed by the two tomcats are exactly the same. Server, don't be surprised]

That's right, I have a very popular online store now. I currently require that I can access it through a 192.168.1.52. If one of the tomcats hangs, it doesn't matter.

Add group 523916260 to understand the follow-up content, there are detailed configuration documents in it, and Daniel is sitting in town~

Modify the configuration file of nginx

I already know the effect that the boss asked me to achieve, so what should I do? I need nginx to integrate the two tomcats above. Go back to the /usr/local/nginx/conf directory and find that there is a configuration file nginx.conf in it.

Open it and edit this thing.

Find the stuff below.

Well, I don't quite understand it, but I don't care, let's do it.

Modify the above pile of stuff and change it to the following

upstream tomcatserver {

server 192.168.1.52:8080;

server 192.168.1.52:9090;

}

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

proxy_pass http://tomcatserver;

index index.html index.htm;

}

[Although it is not important, but explain the above points of attention]

1. The tomcatserver in the Upstream tomcatserver must be consistent with the http://tomcatsetver in the proxy_pass below

2. Upstream tomcatserver specifies the location of your two tomcats. If you are willing, it is no problem to add a few more tomcats.

Reload nginx after modifying the configuration

./nginx -s reload

Test effect

back to browser

Well, it's good, now I can access my tomcat by accessing nginx, okay, I will stop a tomcat

I stopped tomcat at 192.168.1.52:8080 and tried

Continue to visit nginx

Perfect, the effect has been achieved.

Well, I have to admit that this is just a simple application of nginx, and there are still big problems, such as the session consistency problem of nginx, and more importantly...

What if this nginx hangs? It seems that I also have to make nginx highly available. If one nginx crashes, another nginx can replace it without manual operation. More content is welcome to join the group to exchange and learn.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325014275&siteId=291194637