You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/11/19 12:04:19 UTC

[GitHub] [apisix] z-yuxie commented on issue #4942: bug: upstreaam response http code 302,then we found it was be redirected to an new port 9080

z-yuxie commented on issue #4942:
URL: https://github.com/apache/apisix/issues/4942#issuecomment-974013329


   @eastearth @nic-chen @tokers 
   您们好,请问这个问题有被解决么?我遇到了与之相同的问题,我去查看了jenkins自己的文档中关于[反向代理](https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-troubleshooting/)的说明,
   ↓上述文档中关于此内容描述的截图
   ![image](https://user-images.githubusercontent.com/28329410/142617683-0354f948-4305-4070-ae3d-fdc4153623ef.png)
   
   根据其中的描述,是jenkins在某些步骤会自己通过302状态码进行重定向,并在http响应头的Location返回要重定向到的地址,但是目前jenkins方面每次返回的Localtion的端口都是apisix的端口,有两种处理方式,其中一种是需要我们在请求头中设置以下参数:
   X-Forwarded-Host: jenkins.qury.me
   X-Forwarded-Port: 80
   X-Forwarded-Proto: https
   
   关于设置请求头的这种方式,这是我尝试过的方法,但都没有效果,jenkins依然返回了带有9080端口的重定向地址:
   1、通过界面的“路由”(routes)中的“请求头重写”功能设置请求头
   ![image](https://user-images.githubusercontent.com/28329410/142616926-0063348a-203f-4ac9-8e4d-f98c543420bf.png)
   ↓这是通过该方式形成的路由配置在“数据编辑器”中展示的样子
   ![image](https://user-images.githubusercontent.com/28329410/142617143-ee344d28-2984-4215-8467-f1ecdcc18212.png)
   1、通过界面的“服务”(service)中的“[proxy-rewrite](https://apisix.apache.org/zh/docs/apisix/plugins/proxy-rewrite)”插件设置请求头
   ![image](https://user-images.githubusercontent.com/28329410/142617380-1220a90f-9af5-4a6e-8d4a-9e2b8df404b7.png)
   ↓这是通过该方式形成的服务配置在“数据编辑器”中展示的样子
   ![image](https://user-images.githubusercontent.com/28329410/142617500-3d37c3b6-f94c-409c-baf0-4aa07110b739.png)
   
   然后因为我不太确定这是jenkins自身的问题还是apisix插件的问题,于是我现在想要试试另一种修改响应头中的Location的方法,请问有什么方式能让我对响应头中的Location进行正则匹配,并进行修改的么?想要的效果大概是这样的:
   response header:
   Location:https://jenkins.xxx.xxx:9080/*
   ↓
   response header:
   Location:https://jenkins.xxx.xxx/*
   
   我知道有个“[response-rewrite](https://apisix.apache.org/zh/docs/apisix/plugins/response-rewrite)”插件可以对上面所说的Location进行修改,但因为该插件提供的说明中并没有对其进行较多的描述,也没有提供类似的改写范例,我并不确定他是否能做到我上面说的这种基于正则的改写,如果可以的话,能否给我说下我应该怎么去配置,谢谢。
   
   除此之外,我目前觉得大概能有效的一种方法是,我将9080端口也开放出去,然后再重新配置一个路由去识别来自9080端口的请求,并将其重新重定向到80端口,但老实说不到万不得已,我并不是太想新开放一个端口,而且这样的处理方式会让多增加一次http的请求,总感觉不太美好。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org