Nginx reverse proxy, load balancing, high availability of keepalived

Source: Internet
Author: User
Tags install openssl nginx server node server nginx reverse proxy nginx load balancing

Nginx reverse proxy, load balancing, high availability of keepalived

 

 

 

 

Nginx reverse proxy, load balancing, high availability of keepalived

 

I. nginx reverse proxy and Server Load balancer

 

1. What is reverse proxy and Server Load balancer?

Strictly speaking, nginx is only used as the nginx proxv reverse proxy, because this reverse proxy function shows the effect of the Server Load balancer cluster, so this article calls it nginx Server Load balancer. So what is the difference between reverse proxy and Server Load balancer?

For general Server Load balancer software, such as the well-known LVS, the function is to forward (or rewrite data packets) and transmit request data packets, the obvious characteristic of the Dr mode is that, from the perspective of the node servers under the Server Load balancer, the received requests are still real users accessing the Server Load balancer client, and the reverse proxy is different, after receiving a request from a user, the reverse proxy re-initiates the request to the node server under the proxy, and finally returns the data to the client user. In the view of the node server, the client user of the accessed node server is the reverse proxy server, rather than the real Website access user.

 

2. nginx Load Balancing Components

 

650) This. width = 650; "src =" http://s2.51cto.com/wyfs02/M00/81/FC/wKioL1dGwUjACgetAABXuTgJjOA483.png "Title =" t9ek_rji5(0@_cr1_otkn9820.s.png "alt =" wkiol1dgwujacgetaabxutgjjoa483.png "/>

 

3. Build an nginx Load Balancing Environment

Two Server Load balancer instances are required for consistent operation.

Installation Steps

Yum install OpenSSL-devel pcrepcre-devel-y

Rpm-Qa OpenSSL-devel PCRE-devel

Mkdir-P/home/oldboy/tools

CD/home/oldboy/tools

Wget-Q http://nginx.org/download/nginx-1.6.3.tar.gz

Ls-l nginx-1.6.3.tar.gz

Useradd www-S/sbin/nologin-m

Tar xf nginx-1.6.3.tar.gz

CD nginx-1.6.3

./Configure -- user = nginx -- group = nginx -- prefix =/application/nginx-1.6.3 -- with-http_stub_status_module -- with-http_ssl_module

Make

Make install

Ln-S/application/nginx-1.6.3/application/nginx

 

 

Edit configuration file

Vim/application/nginx/CONF/nginx. conf

 

Worker_processes 1;

Events {

Worker_connections 1024;

}

HTTP {

Include mime. types;

Default_type application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

 

Upstream server_pools {

Server 10.0.0.7: 80 Weight = 1;

Server 10.0.0.8: 80 Weight = 1;

}

 

Server {

Listen 80;

SERVER_NAME bbs.etiantian.org;

Location /{

Proxy_pass http: // server_pools;

Proxy_set_header host $ host;

Proxy_set_header X-forwarded-for $ remote_addr;

}

}

Server {

Listen 80;

SERVER_NAME blog.etiantian.org;

Location /{

Proxy_pass http: // server_pools;

Proxy_set_header host $ host;

Proxy_set_header X-forwarded-for $ remote_addr;

}

}

}

 

Test:

[[Email protected] conf] # curl www.etiantian.org

WWW

[[Email protected] conf] # curl www.etiantian.org

Apache WWW

 

 

Ii. Install high availability

 

The installation steps must be the same for both Server Load balancer instances.

 

1. Specific steps

 

Install yum

Yum install keepalived-y

 

Modify the configuration file master configuration file

Vim/etc/keepalived. conf

! Configuration file for keepalived

 

Global_defs {

Notification_email {

[Email protected]

}

Notification_email_from [email protected]

Smtp_server 192.168.200.1

Smtp_connect_timeout 30

Router_id lvs_devel

}

 

Vrrp_instance vi_1 {

State master

Interface eth0

Virtual_router_id 51

Priority150

Advert_int 1

Authentication {

Auth_type pass

Auth_pass 1111

}

Virtual_ipaddress {

10.0.0.3/24 Dev eth0 label eth0: 1

}

}

Modify the sub-configuration file

Vim/etc/keepalived. conf

! Configuration file for keepalived

 

Global_defs {

Notification_email {

[Email protected]

}

Notification_email_from [email protected]

Smtp_server 192.168.200.1

Smtp_connect_timeout 30

Router_id lvs_devel

}

 

Vrrp_instance vi_1 {

State backup

Interface eth0

Virtual_router_id 51

Priority100

Advert_int 1

Authentication {

Auth_type pass

Auth_pass 1111

}

Virtual_ipaddress {

10.0.0.3/24 Dev eth0 label eth0: 1

}

}

 

 

 

 

 

 

 

 

 


This article is from the "11255195" blog, please be sure to keep this source http://11265195.blog.51cto.com/11255195/1783551

Nginx reverse proxy, load balancing, high availability of keepalived

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.