微服务网关有很多比如:Zuul 2、SpringCLoud Gateway、Kong、OpenResty等
Nginx 只是最简单的一种
简单的例子🌰
upstream server2 {
server 192.168.0.1:80;
server 192.168.0.2:80;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
// /api/s1 转发到http://192.168.0.3:80;
location /api/s1 {
proxy_pass http://192.168.0.3:80;
}
// /api/s1 转发到http://server2;
location /api/s2 {
proxy_pass http://server2;
}
}
评论 (0)