码迷,mamicode.com
首页 > 其他好文 > 详细

tengine安装,haproxy访问不同路径对接不同集群

时间:2020-06-22 09:24:12      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:roo   location   官网   man   tween   nta   round   cst   不同   

tengine安装

下载包:在官网 http://tengine.taobao.org/download_cn.html下载各种版本的tengine包

./configure
make
make install

将tengine设置为service服务

cd /usr/lib/systemd/system
vi nginx.service
[Unit]
Description=nginx performance web server
Documentation=http://tengine.taobao.org/documentation_cn.html
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

修改/usr/local/nginx/conf/nginx.conf文件
添加:

pid /var/run/nginx.pid;

systemctl enable nginx
systemctl start nginx
systemctl status nginx

实现api.x.com代理9001端口

192.168.115.128机器修改nginx.conf

 server {
        listen       80;
        server_name  api.x.com;

        location / {
            root   html;
            proxy_pass http://192.168.115.129:9001; #另外一台的nginx监听9001端口
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

haproxy实现7层代理,访问不同路径对应不同集群

haproxy.conf配置文件修改


frontend  main *:5000
    acl url_static1       path_beg       -i /static /images /javascript /stylesheets /a   #不同的访问路径
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static1          if url_static1   #a集群

    acl url_static2      path_beg       -i /static /images /javascript /stylesheets /b   #不同的访问路径
    use_backend static2          if url_static2   #b集群
    default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance     roundrobin
    server  app1 192.168.115.128:80 check
    server  app2 192.168.115.129:80 check

backend static1    #a集群
    balance     roundrobin
    server static1 192.168.115.128:80 check

backend static2   #b集群
    balance     roundrobin
    server static2 192.168.115.129:80 check

访问a集群:
技术图片

访问b集群:
技术图片

tengine安装,haproxy访问不同路径对接不同集群

标签:roo   location   官网   man   tween   nta   round   cst   不同   

原文地址:https://blog.51cto.com/13159674/2506201

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!