Haproxy achieves static-dynamic Separation

Source: Internet
Author: User
Tags syslog haproxy

This section describes the knowledge of haproxy.

Haproxy provides high availability, Server Load balancer, and TCP and HTTP application-based proxy. It supports Virtual Hosts and is a free, fast, and reliable solution. Haproxy is especially suitable for websites with extremely high loads, which usually require session persistence or layer-7 processing. Haproxy runs on the current hardware and supports tens of thousands of concurrent connections. In addition, its running mode enables it to be easily and securely integrated into your current architecture, while protecting your web servers from being exposed to the network.

Okay. Let's implement this process.

Experiment topology:

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201409/22/8733640_1411374276dcI0.png "Height =" 376 "/>

The proxy server acts as a proxy for two internal Web Services, one of which is a dynamic content server and the other is a static content server, haproxy automatically identifies whether the request content is dynamic or static, and distributes the request to their respective servers for response.

Dynamic Server

The PHP service is installed on this server. Here I directly install yum. Therefore, you can respond to a PHP request and place a PHP webpage on the home page. Note that you still need to modify some options in the configuration file of the httpd server.

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201409/22/8733640_1411374277bYtK.png "Height =" 160 "/>

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201409/22/8733640_1411374277eV7F.png "Height =" 79 "/>

Static Server

PHP is not installed on the server, and only a common home page is placed in the following directory.

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201409/22/8733640_14113742774j1G.png "Height =" 52 "/>

 

Proxy Server

Install haproxy directly in yum

Modify configuration file

[[Email protected] ~] # Vim/etc/haproxy. cfg

 

 

# ----------------------------------------------------------------------- # Example configuration for a possible web application. see the # Full configuration options online. # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt # OVERVIEW # global settings # ------------------------------------------------------------------------- Global # To have these messages end up in/var/log/haproxy. log you will # Need To: #1) Configure syslog To accept network log events. this is done # by adding the '-R' option to the syslogd_options in #/etc/sysconfig/syslog #2) configure local2 events to go to the/var/log/haproxy. log # file. A line like the following can be added to #/etc/sysconfig/syslog # local2. */var/log/haproxy. log # log 127.0.0.1 local2 chroot/var/lib/haproxy # The global configuration end does not need to change pidfile/var/run/haproxy. PID maxconn 4000 user haproxy group haproxy daemon # Turn on stats UNIX socket stats socket/var/lib/haproxy/stats # response # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block # modify defaults mode HTTP log global option httplog option dontlognull option http-server-close option forwardfor Login T 127.0.0.0/8 option redispatch retries 3 timeout http-Request 10 s timeout queue 1 m timeout connect 10 s timeout client 1 m timeout Server 1 m timeout http-keep-alive 10 s timeout check 10 s maxconn 3000 # timeout # Main frontend which proxys the backends # --------------------------------------------------------------------- frontend main BIND: 80 # bind the port ACL url_static path_beg-I/static/images/JavaScript/stylesheets # define the static content prefix ACL url_static path_end-I. JPG. GIF. PNG. CSS. JS. html # define static content suffix use_backend static if url_static default_backend app # suffix # static backend for serving up images, stylesheets and such # define backend static balance roundrobin server static 172.16.6.1: 80 check # define the backend static Content Server # rules # Round Robin balancing between the various backends # define backend app balance roundrobin server app1 172.16.6.2: 80 check # define the backend Dynamic Content Server

Configure and start the service

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201409/22/8733640_1411374277dx06.png "Height =" 45 "/>

Now we can start testing.

Static webpage:

650) This. width = 650; "Title =" qq 40922163626.jpg "src =" http://s3.51cto.com/wyfs02/M00/49/F5/wKioL1Qf38fSu1RgAADmDxj8oQI613.jpg "alt =" wkiol110838fsu1rgaadmdxj8oqi613.jpg "/>

Dynamic Webpage:

650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201409/22/8733640_1411374278tfqD.png "Height =" 363 "/>

OK, so we can implement the simplest static and dynamic separation. Thank you!

This article from the Linux cainiao it Road, "blog, please be sure to keep this source http://wiggin.blog.51cto.com/8733640/1556989

Haproxy achieves static-dynamic Separation

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.