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

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

问题描述

我有一个带有静态文件的express Web服务器.我们将此称为我的express-deployment.

我想用我的ingress-nginx来提供我的express-deployment中的静态文件,而无需实际访问我的快速服务器.

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

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

解决方案

理论上,您可以将RWX模式下的PV安装到express和ingress上,并为nginx-ingress pod提供自定义配置,但这应该是避免. Ingress Controller的职责之一是-实施集群中定义的Ingress规则.要提供静态内容,您应该有一个可以做到这一点的Pod,这的确意味着.在堆栈中运行第二个Nginx.事实是,您应该将入口控制器视为提供通用集群功能的基础架构的一部分,并且从某个位置(或将容器版本化/构建为Docker映像的情况下提供容器)提供静态文件实际上是应用程序的一部分. /p>

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

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

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.

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)

解决方案

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天全站免登陆