[Linux] nginx tomcat performs load balancing, nginxtomcat

Source: Internet
Author: User

[Linux] nginx tomcat performs load balancing, nginxtomcat

I used nginx as a web reverse proxy and did not perform load balancing. Today I have a student who needs to perform Load Balancing for tomcat. I have also studied it.

There are two machines in total. Two tomcat servers are deployed on one physical machine (win7) and started on different ports. Place the vm (centos) nginx In the vm and perform Load Balancing for tomcat.

  • Inux ip: 192.168.37.129
  • Win ip: 192.168.37.1

First, ensure that the two hosts can ping each other and the responding port is open.

  • Use 80 on nginx
  • Tomcat1 uses 8081 tomcat2 uses 8080
  • The installation and start of nginx and tomcat are not mentioned, especially in windows. In case of any difficulties, you can use it in Baidu.
  • Install and start tomcat in windows and start multiple tomcat in one system. In order to differentiate the differences between tomcat, add some marks to the html of the home page.
  • Nginx version 1.4 tomcat version 6.0
  • Two tomcat instances can be started normally, and nginx instances can also be used normally. the browser on win can normally access three webpages.
    • Http: // 192.168.37.1: 8081/
    • Http: // 192.168.37.1: 8080/
    • Http: // 192.168.37.129/

Then configure nginx:

[Root @ localhost conf] # cat/etc/nginx. conf

#user  nobody;worker_processes  1;events {    worker_connections  1024;} http {    include       mime.types;    default_type  application/octet-stream;     upstream localhost{        server 192.168.37.1:8080 weight=2;        server 192.168.37.1:8081 weight=1;        #ip_hash;    }     sendfile        on;    keepalive_timeout  65;     server {        listen       80;        server_name  localhost;         location / {            proxy_connect_timeout  3;            #proxy_redirect        off;            proxy_send_timeout     30;            proxy_read_timeout     30;            proxy_pass      http://localhost;        }         error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }}

The restart of nginx does not take effect. It is found that the startup configuration file is incorrect. You can use nginx-c/etc/nginx. conf to specify the path to accompany the configuration file.
Of course, this is the simplest round robin. There are no other strategies, and the experiment is basically successful.

This article from the "orangleliu notebook" blog, reprint please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41251397

Author: orangleliu


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.