[Linux]nginx Tomcat doing load balancing

Source: Internet
Author: User

Before using Nginx did the Web reverse proxy, did not do load balancing, today there is a classmate need to do Tomcat load balancing, I also studied.

There are altogether 2 machines, one physical machine (Win7) that deploys 2 tomcat, using a different port to boot.

Virtual machine in VM (CentOS) nginx, load balance for tomcat.

    • Inux ip:192.168.37.129
    • Win ip:192.168.37.1

First, ensure that two hosts are able to ping each other, responding to the port open.

    • nginx using the
    • TOMCAT1 using 8081 tomcat2 using 8080
    • nginx,tomcat installation and startup is not said, especially under Windows very easy. In the face of difficulties Baidu will be able to.

    • windows installation start tomcat  and   a system to start multiple tomcat  in order to differentiate each tomcat from the other. Add some logos to the HTML on the homepage.

    • nginx version number 1.4 Tomcat version number 6.0
    • 2 Tomcat instances can start normally, Nginx instances can also be used normally, win on the browser can normally visit 3 pages
      • http ://192.168.37.1:8081/
      • http://192.168.37.1:8080/
      • http:// 192.168.37.129/

Then start configuring Nginx:

[Email protected] conf]# cat/etc/nginx/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 - 502 503 504  /50x.HTML; location  =    / 50x   html  {  root html; } }}

This How to restart Nginx did not take effect, the last discovery is due to the boot configuration file is incorrect. The ability to specify the path to accompany the configuration file via Nginx-c/etc/nginx/nginx.conf.
Of course, here is the simplest polling, no other strategy, the experiment is basically successful.

This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41251397

Orangleliu


[Linux]nginx Tomcat doing load balancing

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.