从 ingress-nginx 提供静态文件 [英] serving static files from ingress-nginx

查看:90
本文介绍了从 ingress-nginx 提供静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有静态文件的 express 网络服务器.我们称之为我的express-deployment.

I have a express web server with static files. Let's call this my express-deployment.

我想使用我的 ingress-nginx 来从我的 express-deployment 提供静态文件,而无需真正访问我的 express 服务器.

I'd like to use my ingress-nginx to serve static files from my express-deployment without ever actually hitting my express server.

nginx 中,这是通过 location 指令完成的,您可以在其中指向本地托管的文件.虽然我在 ingress-nginx configMap 中看到了 locations-snippet 的选项,但我不完全确定我将如何获得这一点另一个容器中的文件.

In nginx this is done with the location directive where you point to files locally hosted. While I see an option for locations-snippet in the ingress-nginx configMap, I'm not entirely sure how I would have this point to files in another container.

这可以用 ingress-nginx 实现吗?如果是这样,我将如何处理?或者,这是否需要在我的快速服务器旁边托管一个 nginx 容器?(似乎很奇怪,我需要 2 个 nginx)

Is this possible with ingress-nginx? If so how would I go about it? Alternatively, is this something that requires an nginx container to be hosted along side my express server? (Seems odd that I would need 2 nginx for that)

推荐答案

理论上,您可以在 RWX 模式下将 PV 安装到 express 和 ingress 并为 nginx-ingress pod 提供自定义配置,但这应该是避免了.Ingress Controller 有一项职责 - 实施在您的集群中定义的 Ingress 规则.要提供静态内容,您应该有一个可以执行此操作的 pod,这确实意味着 ie.在您的堆栈中运行第二个 nginx.问题是,您应该将入口控制器视为提供通用集群功能的基础设施的一部分,并且从某个地方(或容器,如果它们被版本控制/构建为 docker 图像)提供静态文件是您应用程序的事实上的一部分.

In theory, you could have a PV in in RWX mode mounted to both express and ingress and provide custom config to the nginx-ingress pods, but that should be avoided. Ingress Controller has one responsibility - implement Ingress rules defined in your cluster. To serve static content you should have a pod that does that, which indeed means ie. running second nginx in your stack. The thing is, that you should treat your ingress controller as part of the infrastructure providing generic cluster functionality, and serving static files from some place (or container if they are versioned/built as docker images) is de facto part of your application.

这篇关于从 ingress-nginx 提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆