首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HAProxy:多个网站,但其中只有一个需要使用所有后端

HAProxy:多个网站,但其中只有一个需要使用所有后端
EN

Stack Overflow用户
提问于 2016-12-07 19:38:13
回答 1查看 973关注 0票数 1

我目前有一个HAproxy负载平衡器设置与2个后端,共3个网站。其中一个网站需要额外的服务器(一个新后端,后端#3),但其他网站不需要使用这个后端。有办法这样做吗?遗憾的是,我无法使用文档来解决这个问题。配置添加。新的后端将是.77。谢谢!

代码语言:javascript
复制
global
	log /dev/log	local0
	log /dev/log	local1 notice
	chroot /var/lib/haproxy
	stats socket /run/haproxy/admin.sock mode 660 level admin
	stats timeout 30s
	user haproxy
	group haproxy
	maxconn 2000
	daemon

	# Default SSL material locations
	ca-base /etc/ssl/certs
	crt-base /etc/ssl/private

	# Default ciphers to use on SSL-enabled listening sockets.
	# For more information, see ciphers(1SSL). This list is from:
	#  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
	ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
	ssl-default-bind-options no-sslv3

	# use 7 of 8 cores, bind stats to the 7th. We want one core for OS and stuff :)
	
	nbproc 7
        cpu-map 1 1
        cpu-map 2 2
        cpu-map 3 3
        cpu-map 4 4
        cpu-map 5 5
        cpu-map 6 6
        cpu-map 7 7
        stats bind-process 7

defaults
	log	global
	mode	http
	option	httplog
	option	dontlognull
	option  forwardfor
	option  http-server-close
        timeout connect 5000
        timeout client  50000
        timeout server  50000
	errorfile 400 /etc/haproxy/errors/400.http
	errorfile 403 /etc/haproxy/errors/403.http
	errorfile 408 /etc/haproxy/errors/408.http
	errorfile 500 /etc/haproxy/errors/500.http
	errorfile 502 /etc/haproxy/errors/502.http
	errorfile 503 /etc/haproxy/errors/503.http
	errorfile 504 /etc/haproxy/errors/504.http


listen stats 192.168.3.78:1936
	stats enable
	stats uri /

frontend www-http
	bind 1.2.3.4:80
	bind 192.168.3.78:80
	reqadd X-Forwarded-Proto:\ http
	bind-process 1
	default_backend www-backend

frontend www-https
	bind 1.2.3.4:443 ssl crt /etc/ssl/private/1.full-pem crt /etc/ssl/private/2.full-pem crt /etc/ssl/private/3.full-pem 
	reqadd X-Forwarded-Proto:\ https
	option forwardfor
	bind-process 2 3 4 5 6
	default_backend www-backend

backend www-backend
	redirect scheme https if !{ ssl_fc }
        cookie SERVERID insert indirect nocache
	server www-1 192.168.3.75:80 check cookie www-1
	server www-2 192.168.3.74:80 check cookie www-2

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-07 21:30:19

关于“后端”一词的注意:您在问题中使用它来描述将被转发请求的服务。为了避免混淆,我将在这里使用serverbackend将是一组server (以匹配HAProxy术语)。

您需要两个backend块,一个带两个server,另一个带三个。在frontend中,使用主机名选择正确的主机名:

代码语言:javascript
复制
frontend www-http
  [...]
  acl host_website3 hdr(host) -i website3.com         # match the new website
  use_backend www-backend-with3 if host_website3      # send it to the correct backend
  default_backend www-backend

backend www-backend
  redirect scheme https if !{ ssl_fc }
  cookie SERVERID insert indirect nocache
  server www-1 192.168.3.75:80 check cookie www-1
  server www-2 192.168.3.74:80 check cookie www-2

backend www-backend-with3                             # new backend here
  redirect scheme https if !{ ssl_fc }
  cookie SERVERID insert indirect nocache
  server www-1 192.168.3.75:80 check cookie www-1
  server www-2 192.168.3.74:80 check cookie www-2
  server www-3 192.168.3.77:80 check cookie www-3     # with a new server here
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41025910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档