【发布时间】:2018-05-04 18:12:08
【问题描述】:
我有 kubernetes-cluster 和一些带有 web-app 的 Pod/容器。 Pod 通过 pod 的名称相互连接,监听端口为 9999(如 security-rest-api:9999、common-rest-api:9999 等)。 使用外部地址http://e.net:30200/ 在外部监听 nginx-pod。
((app-pods:9999)-(nginx-pod:80)-(nginx-service:30200))-网络
Nginx 使用以下配置与 app-pod 进行交互。
server {
listen 80;
server_name e.net;
location / {
proxy_pass http://web-console:9999/;
proxy_redirect http://web-console:9999/ http://e.net:30200/;
}
location /common {
proxy_pass http://common-rest-api:9999/common;
proxy_redirect http://common-rest-api:9999/ http://e.net:30200/;
}
location /security {
proxy_pass http://security-rest-api:9999/security;
proxy_redirect http://security-rest-api:9999/ http://e.net:30200/;
} }
它工作得很好,但我有一个来自 app-pods 的 302 回复的问题:
如果我尝试登录我的应用程序,我会收到 302 回复标题:
HTTP/1.1 302 Found
Connection: keep-alive
Content-Length: 0
Date: Wed, 25 Apr 2018 10:37:50 GMT
Location: http://e.net:30200/security/rest/auth/login.html?callbackUrl=http://security-rest-api:9999/security/rest/namespace
Server: nginx/1.13.9
App-pods 从容器网络内的主机请求标头生成 URL 参数“callbackUrl”和此 URL 参数以到达端点浏览器。当然,下一个请求会得到 404 码。
我无法编辑 app-code(在 app-pods 中不要使用 nginx),但我想将 Location 中的 'security-rest-api:9999' 更改为 'e.net:30200' 参数302 回复标头。我该怎么做?
redirect 不适合,因为这会生成新的 302-reply 并不能解决我的问题。 sub_filter 仅更改回复正文,但不更改回复头(位置参数在哪里)。 request_uri 也不起作用,因为此参数仅适用于请求标头。
【问题讨论】:
-
您的应用需要了解并考虑到可能需要向用户呈现不同 URL 的事实。许多其他应用程序(例如 Jenkins)就是这样做的。
标签: nginx kubernetes