[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, which is started with a different port. 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 can ping each other and the port of the response is open.

    • Use 80 on Nginx
    • TOMCAT1 using the 8081 tomcat2 8080
    • Nginx,tomcat installation and start-up is not said, especially under Windows is very simple, encounter difficulties under Baidu can be.
    • Windows Setup launches Tomcat and a system that launches multiple Tomcat to differentiate each tomcat, add some flags to the page's HTML.
    • Nginx version 1.4 Tomcat version 6.0
    • 2 Tomcat instances can start normally, nginx instance can be used normally, the browser in win can access 3 pages normally.
      • 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, and finally found that because the boot configuration file is not correct, you can use Nginx-c/etc/nginx/nginx.conf to specify the path to accompany the configuration file.
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.