配置同一个域名,不同的path,访问不同的service
# 重写URL
# 当您访问 http://<ingress_ip>/foo/bar 时,nginx ingress controller 将把请求路由到 foo-service 的 80 端口,并将原始请求的路径 /foo/bar 重写为 /bar。
# nginx.ingress.kubernetes.io/rewrite-target: /
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-lava-mall-client-ingress
namespace: test-app
annotations:
# location ^~ /store-api 使用正则匹配
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/server-snippet:
location ^~ /index/common/getQandAListi {
rewrite ^(.*)$ https://www.bb.com$1 permanent;
}
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
nginx.ingress.kubernetes.io/configuration-snippet:
rewrite ^/store-api/(.*)$ /$1 break;
spec:
tls:
- hosts:
- a.yht.com
secretName: yht-tls-secret
rules:
- host: a.yht.com
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: test-lava-mall-client-selector-service
port:
number: 80
- host: a.yht.com
http:
paths:
- path: "/store-api"
pathType: Prefix
backend:
service:
name: test-store-api-selector-service
port:
number: 80
效果展示如下:
server {
listen 443 ssl http2;
server_name a.yht.com;
location ^~ /index/common/getQandAListi {
rewrite ^(.*)$ https://www.bb.com$1 permanent;
}
location / {
if (!-f $request_filename){
proxy_pass https:/test-lava-mall-client-selector-service.yht.com;
}
}
location ^~ /store-api {
rewrite ^/store-api/(.*)$ /$1 break;
proxy_pass http://test-store-api-selector-service.yht.com
}
}
标签:Ingress,service,ingress,nginx,api,yht,com,store
From: https://blog.51cto.com/yht1990/6207551