简体   繁体   English

如何在kubernetes Nginx入口控制器API对象中配置本地化的URL

[英]How to configure localized URLs in kubernetes nginx ingress controller API object

I have a cluster in Azure AKS with 1 node. 我在具有1个节点的Azure AKS中有一个群集。

On that cluster I have two back-end services. 在该群集上,我有两个后端服务。

Each back-end service is a web app. 每个后端服务都是一个Web应用程序。

I have a domain mydomain.com. 我有一个域名mydomain.com。

Each app will need to be configured with its own path rule in the ingress object. 每个应用都需要在入口对象中配置自己的路径规则。

Web app 1s (let's call this one the homepage app) target URL needs to be either of the following: Web应用程序1s(我们称其为主页应用程序)目标URL必须为以下任意一个:

US version of the site: mydomain.com
Swedish version of the site: mydomain.com/se/sv-sv/hem 
Any other location/language version of the site: mydomain.com/xx/yy-xx/abcdefgh

Web app 2s (let's call this one the whitepony app) target URL needs to be either of the following: Web应用程序2s(我们称其为whitepony应用程序)目标URL必须为以下任意一项:

US version of the site: mydomain.com/us/en-us/whitepony
Swedish version of the site: mydomain.com/se/sv-sv/whitepony
Any other location/language version of the site: mydomain.com/xx/yy-xx/whitepony 

(The whitepony apps target path segment is called whitepony regardless of location/language) (无论位置/语言如何,whitepony应用程序的目标路径段都称为whitepony)

Now to my question. 现在我的问题。

How can I configure these rules in an ingress API object? 如何在Ingress API对象中配置这些规则?

Can I use prefixes in the path rules? 我可以在路径规则中使用前缀吗?

Or do I need to use regular expressions? 还是我需要使用正则表达式?

And what about the special case of the US version of the homepage app, where I'm not using any prefixes/extra URL segments? 在美国版本的首页应用程序的特殊情况下,我不使用任何前缀/额外的URL段呢?

Can I use conditions in the ingress object? 我可以在入口对象中使用条件吗?

Or how would you configure the ingress resource object to meet all the above requirements? 或者,您将如何配置入口资源对象以满足所有上述要求?

Note that I know and have successfully configured multiple back-end services using path rules in an ingress object. 请注意,我知道并且已经使用入口对象中的路径规则成功配置了多个后端服务。

But without prefixes or extra URL segments. 但没有前缀或多余的URL段。

I won't give you fully working example on how to specify rules in ingress resource to meet your requirements, I would rather like to share with you some hints: 我不会为您提供有关如何在入口资源中指定规则以满足您的要求的完整示例,我想与您分享一些提示:

  1. Yes, you will need regular expressions to achieve it, and here is the example of doing it directly with NGINX directives based on example of wordpress multi-language site. 是的,您将需要正则表达式来实现它, 是基于wordpress多语言站点示例的直接使用NGINX指令执行操作的示例。

  2. You don't need to define these re-write rules with annotations, you can use for that pure NGINX config style, by supplying appropriate inline NGINX config file inside ConfigMap, here is the example on how to achieve this. 您不需要使用批注定义这些重写规则,可以通过在ConfigMap中提供适当的内联NGINX配置文件来用于纯NGINX配置样式, 此处是有关如何实现此目的的示例。

I hope this will help you 我希望这能帮到您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM