Nginx reverse proxy and server group status

Source: Internet
Author: User
Tags nginx reverse proxy

Implementation of Nginx Proxy (seven-layer load balancing);



Topology diagram:

WEB01 WEB02

|192.168.1.20 |192.168.1.21

-----------------------------

|192.168.1.254

Nginx (reverse proxy);

|1.1.1.254

|

Client (1.1.1.1);



Requirements: client1.1.1.1 can be accessed through the reverse proxy 1.1.1.254 two Web services to the intranet, WEB01 performance is better, the weight value is two;



* * Due to the limited resources, with IP virtual host to implement two web; (Web server Apache);



Implementation process:

1. First configure two Web servers;

[Email protected] local]# ifconfig

Eth0 Link encap:ethernet HWaddr 00:0c:29:07:6d:a0

inet addr:192.168.1.20 bcast:192.168.1.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE07:6DA0/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:30 errors:0 dropped:0 overruns:0 frame:0

TX packets:31 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:4318 (4.2 KiB) TX bytes:5539 (5.4 KiB)


Eth0:1 Link encap:ethernet HWaddr 00:0c:29:07:6d:a0

inet addr:192.168.1.21 bcast:192.168.255.247 mask:255.255.255.0

Up broadcast RUNNING multicast mtu:1500 metric:1


To configure a virtual host:

[Email protected] conf.d]# vim virtualhost.conf

<virtualhost 192.168.1.20:80>

Documentroot/www

ServerName www.bxn.com

Customlog Logs/www20-access_log Common

</VirtualHost>

<virtualhost 192.168.1.21:80>

Documentroot/bbs

ServerName bbs.bxn.com

Customlog Logs/bbs21-access_log Common

</VirtualHost>


[Email protected] bbs]#/etc/init.d/httpd restart


[Email protected] bbs]# elinks--dump 192.168.1.20

192.168.1.20:www

[Email protected] bbs]# elinks--dump 192.168.1.21

192.168.1.21:bbs


Web service configuration completed;



2. Configure the Reverse proxy:

Installation Nginx process: Source installation: Write briefly;

Groupadd Nginx

Useradd-m-G Nginx

Yum install-y pcre Pcre-devel

Yum Install-y OpenSSL Openssl-devel

./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_stub_status_module

Make && make install



Reverse proxy configuration:

[Email protected] nginx]# cd/usr/local/nginx/conf/


[Email protected] conf]# grep-v ' #\|^$ ' nginx.conf >nginx2.conf


[Email protected] conf]# vim nginx2.conf

Worker_processes 1;

Events {

Worker_connections 1024;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

Upstream Webgrp {

Server 192.168.1.20 weight=2;

Server 192.168.1.10 weight=1;

}

Upstream is the key;

server {

Listen 80;

server_name localhost;

Location/{

root HTML;

Index index.html index.htm;

Proxy_pass http://webgrp//and this;

}

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

}



[Email protected] sbin]#/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx2.conf


[Email protected] conf]# NETSTAT-TULNP |grep nginx

TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2590/nginx


3. In the client 1.1.1.1 test;

ELinks 1.1.1.254[[email protected] ~]# ifconfig eth0

Eth0 Link encap:ethernet HWaddr 00:0c:29:19:1b:0d

inet addr:1.1.1.1 bcast:1.1.1.255 mask:255.255.255.0



[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.21:bbs

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.21:bbs

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

The client can see that the test has been successful;



* Knowledge Points:

Connection status of the server group: determines how the connection request is distributed:


Poll: Nginx default connection request distribution method;

Ip_hash: When the same client connects, only the same server is connected; (resolves the session problem);


Weight: Weight: Distribute the request according to the weight proportion;

Fair: Who connection request processing fast, to whom, by default is not supported (need to install third-party software);


Using the Ip_hash method:


Configuration:

Upstream Webgrp {

Ip_hash;

Server 192.168.1.20;

Server 192.168.1.21;

}


Test:

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

[Email protected] ~]# elinks--dump 1.1.1.254

192.168.1.20:www

* * You can see that each access is the same Web server;







This article is from the "9379746" blog, please be sure to keep this source http://9389746.blog.51cto.com/9379746/1585185

Nginx reverse proxy and server group status

Related Article

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.