二、编译安装tengine,配置相关虚拟主机及配置haproxy

1、编译安装tengine,配置虚拟主机实现api.x.com

1.1 安装相关依赖包

sudo apt-get install openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev make make-guile gcc -y

查看libpcre3是否安装:dpkg -l | grep libpcre3

1.2 创建nginx用户

#groupadd nginx

#useradd -g nginx -s /sbin/nologin nginx

#id nginx

 uid=1001(nginx) gid=1001(nginx) groups=1001(nginx)

1.3 安装Tengine-2.3.2

如果需要兼容Nginx则使用之前Nginx的编译:/apps/nginx/sbin/nginx -V  

#./configure --prefix=/apps/tengine-2.3.2 --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

 make && make install 

创建软连接

#ln -sv /apps/tengine-2.3.2/sbin/nginx /usr/sbin/nginx

'/usr/sbin/nginx' -> '/apps/tengine-2.3.2/sbin/nginx'

1.4 配置server监听9001端口


设置页面

#echo 9001端口网页 > index.html

#cat /data/html/index.html 

9001端口网页

1.5 设置api.x.com代理9001


1.6 访问api.x.com



2、配置haproxy,实现/a路径代理转发到a集群,实现/b路径代理转发到b集群

2.1 部署规划:

192.168.37.47:haproxy服务器

192.168.37.57:a集群环境

192.168.37.67:b集群环境

192.168.37.18:默认环境

2.2 haproxy安装配置

yum安装:yum install haproxy -y

修改配置文件:

[root@cent744 ~]#vim /etc/haproxy/haproxy.cfg 

  frontend web_prot_80

  bind 0.0.0.0:80

  mode http

  acl web_port  path_beg -i /a   

  acl mob_port  path_beg -i /b   

  use_backend web_port_http_nodes if web_port

  use_backend mob_port_http_nodes if mob_port

  default_backend backup_nodes   

  backend web_port_http_nodes

  server server1  192.168.37.57:80 weight 1 check port 80 inter 3s fall 2 rise 5

  backend mob_port_http_nodes

  server server2  192.168.37.67:80  weight 1 check port 80 inter 3s fall 2 rise 5

  backend backup_nodes

  server server3  192.168.37.18:80 weight 1 check port 80 inter 3s fall 2 rise 5

2.3 其他配置

2.3.1 a环境:

yum install nginx -y

cd /usr/share/nginx/html/

echo aaa > ./a/index.html

systemctl start nginx

2.3.2  b环境:

yum install nginx -y

yum install nginx -y

cd /usr/share/nginx/html/

mkdir b

echo bbb > ./b/index.html

systemctl start nginx

2.3.4  默认环境:

yum install nginx -y

cd /usr/share/nginx/html/

echo 默认 > index.html

systemctl start nginx

2.4 实现

原网址


代理后


你可能感兴趣的:(二、编译安装tengine,配置相关虚拟主机及配置haproxy)