Graphic commentary, initial knowledge of Nginx, simple configuration to achieve load balancing (Ubuntu + Nginx + tomcat)

Source: Internet
Author: User
Tags nginx server nginx reverse proxy

Work needs, research the Nginx reverse proxy to achieve load balancing, search the web for a tutorial, mostly vague, so write this, right when summed up, convenient to see later, if you can help some people need, it is better

First, the requirements, the domain name to build the Nginx Server A, and then by a load balancer to the Server B and server C with Tomcat (do not know "from a load balanced to B, C" This is correct)

          

First say the environment:

Server ABC are gifted Kylin (Ubuntukylin) 14.04

Server A is equipped with Nginx1.6.3

Server B, c use Tomcat6

Preparatory work:

1. Set Server A's IP to 192.168.1.109, Server B's IP is 192.168.1.110, Server B's IP is 192.168.1.111

2. See if the system installs the g++ compiler

g++--version

If version information is displayed, installation is not required. If the prompt is not found, first install the g++ compiler

       

3. Installing the Pcre,pcre library is the basis for implementing Perl-style regular expressions

cd/usr/local/srcwget ftp://tar-zxvf pcre-8.35. TAR.GZCD pcre-8.35. /Configuremakemake Install

4. Installing the Zlib Library

Cd/usr/local/srcwget HTTP://ZLIB.NET/ZLIB-1.2.8.TAR.GZTAR-ZXVF ZLIB-1.2.8.TAR.GZCD Zlib-1.2.8./configuremakemake Install

5. Installing Nginx

Nginx has stable version and the main version, I chose the stable version of 1.6.3, (http://nginx.org/en/download.html)

 

cd/usr/local/srcwget http://nginx.org/download/nginx-1.6.3.tar.gztar-zxvf nginx-  1.6. 3 . TAR.GZCD Nginx-1.6. 3 . /configure--prefix=/usr/local/nginx  //here means installing Nginx in/usr/local/nginx directory makemake Install

At this point, nginx installation is complete, the following command is the start Nginx:

cd/usr/local/nginx/sbin. /nginx

After startup, the browser enters Server A's ip:192.168.1.109, if a screen appears, it indicates that Nginx installation is successful

  

Here to configure reverse proxy load Balancing

Configure Server B and C to allow access to Server B to prompt "This is page A" to access server C Prompt "This is page B"

Then edit the nginx configuration file and save

User Comdev comdev;worker_processes10; #error_log logs/Error.log, #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; #最大文件描述符worker_rlimit_nofile51200; events {use epoll; Worker_connections51200;}      HTTP {include mime.types; Default_type Application/octet-stream; Keepalive_timeout120;      Tcp_nodelay on; Upstream192.168.1.109{Server192.168.1.110:8080; Server192.168.1.111:8080; } Server {Listen80; server_name192.168.1.109; Location/{proxy_pass http://192.168.1.109;Proxy_set_header Host $host; Proxy_set_header X-real-IP $remote _addr; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for; }      }      }

Re-start Nginx

Method Reference: Http://www.cnblogs.com/derekchen/archive/2011/02/17/1957209.html

Then access the 192.168.1.109, the "This is page A" will be displayed, refresh, the "This is page B" will be displayed

At this point, the Nginx reverse proxy implementation of a simple load balancing example is completed

Of course, Nginx can also configure n multi-content, I one by one groping and then write up

Organized from:

Http://www.nginx.cn/install
http://blog.csdn.net/user_longling/article/details/44646465
Http://developer.51cto.com/art/201407/446626.htm
http://zyan.cc/post/306/
http://www.php100.com/html/program/nginx/2013/0905/5525.html###
http://ari.iteye.com/blog/833153
Http://www.cnblogs.com/derekchen/archive/2011/02/17/1957209.html

Graphic commentary, initial knowledge of Nginx, simple configuration to achieve load balancing (Ubuntu + Nginx + tomcat)

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.