<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>浮山狼de博客 &#187; 新技术</title>
	<atom:link href="https://www.fushanlang.com/category/%e6%96%b0%e6%8a%80%e6%9c%af/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fushanlang.com</link>
	<description>next station - 下一站，活在当下，且行且思</description>
	<lastBuildDate>Sat, 29 Nov 2014 15:14:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.5</generator>
	<item>
		<title>HAProxy &#8211; route by domain name</title>
		<link>https://www.fushanlang.com/haproxy-route-by-domain-name-2336/</link>
		<comments>https://www.fushanlang.com/haproxy-route-by-domain-name-2336/#comments</comments>
		<pubDate>Thu, 07 Nov 2013 01:30:07 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[新技术]]></category>
		<category><![CDATA[haproxy]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2336</guid>
		<description><![CDATA[<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;by Sean Mcgary on September 28, 2013</p> <p>http://seanmcgary.com/posts/haproxy&#8212;route-by-domain-name</p> <p>&#160;</p> <p>I tend to build a lot of web applications in NodeJS using the Express.js webserver. When you have a few of these apps running on one server, you generally want to run them on unique ports and put some kind of proxy in front of <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/haproxy-route-by-domain-name-2336/">HAProxy &#8211; route by domain name</a></span>]]></description>
				<content:encoded><![CDATA[<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;by Sean Mcgary on September 28, 2013</p>
<p><a href="http://seanmcgary.com/posts/haproxy---route-by-domain-name">http://seanmcgary.com/posts/haproxy&#8212;route-by-domain-name</a></p>
<p>&nbsp;</p>
<p>I tend to build a lot of web applications in NodeJS using the Express.js webserver. When you have a few of these apps running on one server, you generally want to run them on unique ports and put some kind of proxy in front of them. Nginx works great for this and Apache can be another decent, though more bloated, alternative. Recently I decided to branch out for the sake of variety and to learn something new. HAProxy filled that role.</p>
<p>For the uninformed, HAProxy is more than just a reverse proxy; it&#8217;s a high performance load balancer. Sites with lots of traffic will use something like HAProxy to funnel traffic to a cluster of web servers or even balance taffic between database servers. But what happens when we want to route multiple domains (or subdomains) to different hosts or clusters?</p>
<p>Setting up a single proxy<br />
First lets take a look at the basics of proxying to an app server.</p>
<p># config for haproxy 1.5.x</p>
<p>global<br />
log 127.0.0.1 local0<br />
log 127.0.0.1 local1 notice<br />
maxconn 4096<br />
user haproxy<br />
group haproxy<br />
daemon</p>
<p>defaults<br />
log global<br />
mode http<br />
option httplog<br />
option dontlognull<br />
option forwardfor<br />
option http-server-close<br />
stats enable<br />
stats auth someuser:somepassword<br />
stats uri /haproxyStats</p>
<p>frontend http-in<br />
bind :80<br />
default_backend web-app-cluster</p>
<p>backend web-app-cluster<br />
balance leastconn<br />
option httpclose<br />
cookie JSESSIONID prefix<br />
server node1 10.0.0.1:8080 cookie A check<br />
server node2 10.0.0.2:8080 cookie A check<br />
server node3 10.0.0.3:8080 cookie A check<br />
So this is a pretty basic config that will loadbalance across 3 application servers, each of which is on a unqiue IP and probably on its own dedicated machine. Generally you&#8217;ll also want to run your load balancer(s) on a different server.</p>
<p>So what does this all mean? global and defaults should be pretty self-explanatory, then we have a frontend and abackend. The frontend, as you can see, tells HAProxy what to bind to and defines a default backend. There are a lot of things that can be specified in the front end and you can also have multiple frontend definitions (for example, if you wanted to provide an unsecure route running on port 80 and SSL on port 443 and have different, or the same, backends for each). We&#8217;ll go over some other options in the multiple domain example.</p>
<p>Diving into multiple domains and ACLs<br />
Now lets take a look at how to route to multiple domains based on matching specific domain names.</p>
<p># config for haproxy 1.5.x</p>
<p>global<br />
log 127.0.0.1 local0<br />
log 127.0.0.1 local1 notice<br />
maxconn 4096<br />
user haproxy<br />
group haproxy<br />
daemon</p>
<p>defaults<br />
log global<br />
mode http<br />
option httplog<br />
option dontlognull<br />
option forwardfor<br />
option http-server-close<br />
stats enable<br />
stats auth someuser:somepassword<br />
stats uri /haproxyStats</p>
<p>frontend http-in<br />
bind *:80</p>
<p># Define hosts<br />
acl host_bacon hdr(host) -i ilovebacon.com<br />
acl host_milkshakes hdr(host) -i bobsmilkshakes.com</p>
<p>## figure out which one to use<br />
use_backend bacon_cluster if host_bacon<br />
use_backend milshake_cluster if host_milkshakes</p>
<p>backend baconcluster<br />
balance leastconn<br />
option httpclose<br />
option forwardfor<br />
cookie JSESSIONID prefix<br />
server node1 10.0.0.1:8080 cookie A check<br />
server node1 10.0.0.2:8080 cookie A check<br />
server node1 10.0.0.3:8080 cookie A check</p>
<p>backend milshake_cluster<br />
balance leastconn<br />
option httpclose<br />
option forwardfor<br />
cookie JSESSIONID prefix<br />
server node1 10.0.0.4:8080 cookie A check<br />
server node1 10.0.0.5:8080 cookie A check<br />
server node1 10.0.0.6:8080 cookie A check<br />
So here we are routing between two applications; ilovebacon.com and bobsmilkshakes.com. Each one has its own cluster of app servers that we want to load balance between. Lets take a closer look at where all the magic happens in the frontend.</p>
<p>frontend http-in<br />
bind *:80</p>
<p># Define hosts<br />
acl host_bacon hdr(host) -i ilovebacon.com<br />
acl host_milkshakes hdr(host) -i bobsmilkshakes.com</p>
<p>## figure out which one to use<br />
use_backend bacon_cluster if host_bacon<br />
use_backend milshake_cluster if host_milkshakes<br />
If you&#8217;ve ever used nginx or Apache as reverse proxies, youd generally set things up using virtual hosts. HAProxy uses the notion of access control lists (acl) which can be used to direct traffic.</p>
<p>After we bind to port 80, we set up two acls. The hdr (short for header) checks the hostname header. We also specify -i to make sure its case insensitive, then provide the domain name that we want to match. You could also setup acls to match routes, file types, file names, etc. If you want to know more, feel free to check the docs. So now we effectively have two variables; host_bacon and host_milkshakes. Then we tell HAProxy what backend to use by checking to see if the variable is true or not. One other thing that we could do after the use_backend checks is specify a default_backend like we did in the first example to act as a catch-all to traffic hitting our load balancer that doesn&#8217;t match either of the domain names.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/haproxy-route-by-domain-name-2336/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iGadget触摸世界无视iphone,ipad其他智能手机</title>
		<link>https://www.fushanlang.com/igadget-touch-the-world-1603/</link>
		<comments>https://www.fushanlang.com/igadget-touch-the-world-1603/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 01:39:54 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[新技术]]></category>
		<category><![CDATA[iGadget]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=1603</guid>
		<description><![CDATA[<p>瑞典的设计公司CHN在于2010年9月11日内瓦召开的CNET EURO正式发布了此项产品，在其展示短片中，igadget系列产品展示了其轻薄的特性和可伸缩的优越功能，产品支持wifi无限网络，可以随意浏览新闻并支持照片共享功能，一切操作都通过触摸屏来实现，此项技术能够被应用在诸如镜子，玻璃隔板等日常家具物件上，改写了个人电脑的传统认知，此项技术被英国的BBC评论为21世纪最具突破性的科技应用。</p> <p></p> ]]></description>
				<content:encoded><![CDATA[<p>瑞典的设计公司CHN在于2010年9月11日内瓦召开的CNET EURO正式发布了此项产品，在其展示短片中，igadget系列产品展示了其轻薄的特性和可伸缩的优越功能，产品支持wifi无限网络，可以随意浏览新闻并支持照片共享功能，一切操作都通过触摸屏来实现，此项技术能够被应用在诸如镜子，玻璃隔板等日常家具物件上，改写了个人电脑的传统认知，此项技术被英国的BBC评论为21世纪最具突破性的科技应用。</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="align" value="middle" /><param name="src" value="http://player.youku.com/player.php/sid/XMjA1OTkyODEy/v.swf" /><param name="quality" value="high" /><embed type="application/x-shockwave-flash" width="480" height="400" src="http://player.youku.com/player.php/sid/XMjA1OTkyODEy/v.swf" align="middle" quality="high"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/igadget-touch-the-world-1603/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.453 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2025-09-19 06:32:46 -->
