Haproxy implements discuz! Dynamic/static Separation

Source: Internet
Author: User
Tags haproxy

Haproxy works in the user space (Layer 7) and can identify data at the application layer (HTTP packets. Therefore, you can schedule requests to different service groups based on different request types. That is, haproxy can identify the request information of HTTP packets for access control;

For example:

A group of servers Process Dynamic Resources: JSP and PHP

A group of servers process static resources, such as images requested by users.

Dynamic servers are not allowed to respond to static resources. JSP or PHP pages are responded to after being executed by the application server. Therefore, to improve the efficiency of the application server in Processing dynamic pages. Static and Dynamic separation is usually required for user requests. Use the layer-7 scheduler to schedule user requests to the specified server. There are also static resources that can be cached, which can also improve the website response speed. Cache static resources to your home using CDN networks ......

Haproxy uses ACL for access control. The format is as follows:

ACL <aclname> <criterion> [flags] [Operator] <value>... ACL list name test standard flag test condition expression

1. The configuration file is as follows:

Frontend main BIND: 80 ACL url_static path_beg-I/static/images -----> use the ACL key to define the access control list: url_static. the conditions for matching the access list are: the URL requested by the user is a URL starting with/static or/images. ACL url_static path_end-I. JPG. GIF. PNG ------> the access control list url_static rule is to perform character matching after the URL of the resource requested by the user. The matching rule is as follows: .jpg or. GIF or. URLs at the end of PNG are matched. Use_backend static if url_static -------> implements ACL access control for user requests. If the access control rules defined by url_static are met, these requests are scheduled to the upstream service with the static identifier. Default_backend webservers ------> requests not matched by the url_static Access Control List are scheduled to the upstream server identified by webservers. Option forwardfor rule t 127.0.0.0/8 backend webservers ------> define the upstream server webservers to respond to your dynamic request balance roundrobin rspadd X-via: app ----> customize a response header. You can view the HTTP packet to know that the request is responded by the group of backend servers. Cookie webserver insert nocache option httpchk server S1 172.16.0.99 cookie S1 check port 80 weight 1 server B1 127.0.0.1: 8080 backup stats enable --------> stats hide-version stats uri/haproxy? Stats stats scope. stats realm haporxy \ statistics stats auth admin: Admin stats admin if truebackend static ---------> define the upstream server static to respond to the user's static request balance roundrobin rspadd X-: static -----> customizes a response header. You can view the HTTP packet to know that the request is responded by the group of backend servers. Option httpchk server S2 172.16.0.88 cookie S2 check port 80 weight 1

Access test:

1. Check which group of servers respond to the dynamic page?

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/F8/wKiom1QgwgXg0bnpAAUVSDZKPZw734.jpg "Title =" haproxy balanced discuz! Static separation 01.png "alt =" wkiom1qgwgxw.bnpaauvsdzkpzw734.jpg "/>


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/F8/wKiom1QgxImDVYbuAAOj91KqcE8526.jpg "Title =" haproxy balanced discuz! Real-time static separation 02.png "alt =" wkiom1qgximdvybuaaoj91kqce8526.jpg "/>

Note:

We can see that dynamic pages are responded by webservers.

2. Check which server group responds to the static page?

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/F8/wKiom1QgwqfBgM-zAAUL8WKm8-g893.jpg "Title =" haproxy balanced discuz! Static and Dynamic separation 03.png "alt =" wKiom1QgwqfBgM-zAAUL8WKm8-g893.jpg "/> View again



650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/F8/wKiom1Qgwt-BtEp9AAM1pWg5THw499.jpg "Title =" haproxy balanced discuz! Actual static separation 03_1.png "alt =" wKiom1Qgwt-BtEp9AAM1pWg5THw499.jpg "/> description:

From the channel, the URL requested by the user is scheduled to the static server group by haproxy.

2. Check the user request JS mode table. Does haproxy schedule the request to the static server group?

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/F8/wKiom1QgxcHRivX_AASI-8oF6Kw995.jpg "Title =" haproxy balanced discuz! Actual static separation 04.png "alt =" wKiom1QgxcHRivX_AASI-8oF6Kw995.jpg "/> description:

From HTTP packet analysis, the user request JS style table is a dynamic request to the service, so the request should not be directed to the static server group. Therefore, modify the haproxy ACL.

2. modify the configuration file of haproxy

frontend main    bind :80    acl  url_static  path_beg  -i /static/images      acl  url_static  path_end  -i .jpg .gif .png    use_backend   static  if url_static    default_backend webservers    option forwardfor  except 127.0.0.0/8

Access Test

1. View user request JS

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/F8/wKiom1QgxsTgZ3ODAANrAxyEto4507.jpg "Title =" haproxy balanced discuz! Static separation 07.png "alt =" wkiom1qgxstgz3odaanraxyeto00007.jpg "/> 2. View requested image resources

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/F8/wKiom1QgxxHyNf8DAARHOmx-Jes787.jpg "Title =" haproxy balanced discuz! Returns the actual static separation 05.png "alt =" wKiom1QgxxHyNf8DAARHOmx-Jes787.jpg "/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/F8/wKiom1QgxziSJe6eAAMsnGMAyk4758.jpg "Title =" haproxy balanced discuz! The actual static separation 06-1.png "alt =" wkiom1qgxzisje6eaamsngmayk4758.jpg "/>.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/F8/wKiom1Qgx1rg4HybAAMizyBR5PI352.jpg "Title =" haproxy balanced discuz! Real-time static separation 06-2.png "alt =" wkiom1qgx1rg4hybaamizybr5pi352.jpg "/>

Note:

After the above modification, the static and dynamic separation can be achieved.


This article is from the "Linux" blog, please be sure to keep this source http://9528du.blog.51cto.com/8979089/1557181

Haproxy implements discuz! Dynamic/static 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.