HAProxy实现前-后端热调试

由于前端用了vue,后端用了go,webpack的proxy是一种策略,可是vue create构建的应用似乎找不到入口,加上对webpack的不熟悉,便用haproxy进行反代调试。前后端任意调试的过程中都不需要停机-构建-启动-看情况的过程,实现了热调试。

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
global
maxconn 4000
daemon
# turn on stats unix socket

defaults
mode http
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 4000

frontend http-in
bind *:80
mode http
acl url_backend path_beg -i /api
use_backend backend_servers if url_backend
default_backend front_servers
backend backend_servers
server imgsrv1 127.0.0.1:4000 check maxconn 1000

backend front_servers
cookie srv insert nocache
server websrv1 127.0.0.1:8080 check maxconn 1000 cookie websrv1

通过如上设置,服务端映射到/api路由下,是4000端口-80端口;客户端映射到/路由下,是8080-80端。这样调试的时候就避开了跨域问题,对往后的部署有更好的非侵入性。

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×