apisix icon indicating copy to clipboard operation
apisix copied to clipboard

help request: 尝试代理 hdfs 的 webui,但是会返回 302 重定向,应该如何配置呢?或者是否有示例

Open wfy-belief opened this issue 1 year ago • 2 comments
trafficstars

Description

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: hadoop-route
spec:
  http:
    - name: namenode
      match:
        hosts:
          - example.com
        paths:
          - /hdfs/*
      backends:
        - serviceName: namenode-service
          servicePort: 9870
      plugins:
        - name: proxy-rewrite
          enable: true
          config:
            regex_uri: [ "^/hdfs/(.*)", "/$2" ]
#        - name: response-rewrite
#          enable: true
#          config:
#            status_code: 302
#            # "body": "{\"code\":\"ok\",\"message\":\"new json body\"}"
#            headers:
#              set:
#                X-Server-id: 3
#                X-Server-status: 'on'
#                X-Server-balancer-addr: '$balancer_ip:$balancer_port'
#                Location: example.com/hdfs/
#            vars:
#              - "[ \"status\",\"==\",403 ]"

然后我请求这个路径的 curl 如下

curl example.com/hdfs/ -vl
* Host  example.com:80 was resolved.
* IPv6: (none)
* IPv4: xxxxx
*   Trying xxxx:80...
* Connected to  example.com (xxxx) port 80
> GET /hdfs/ HTTP/1.1
> Host:  example.com
> User-Agent: curl/8.6.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Content-Type: text/plain;charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< Date: Mon, 17 Jun 2024 12:53:07 GMT
< Cache-Control: no-cache
< Expires: Mon, 17 Jun 2024 12:53:07 GMT
< Pragma: no-cache
< X-Content-Type-Options: nosniff
< X-FRAME-OPTIONS: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Location: http:// example.com/index.html
< Server: APISIX/3.9.1
<
* Connection #0 to host  left intact

这个是否只能开发自定义插件解决了呢 QAQ

Environment

  • APISIX version (run apisix version):
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):

wfy-belief avatar Jun 17 '24 12:06 wfy-belief

个人感觉,可能的两种方法:

1 用apisix 来处理这个302, 添加一条route, 直接把 / 代理到 /index.html 2. 用response_write, 把302的返回,添加你的 “hdfs” 这段代理头

hanqingwu avatar Jun 21 '24 06:06 hanqingwu

@wfy-belief 你可以使用 ApisixUpstream 的 healthCheck.active 主动健康检测9870端口的 /isActive 路径,这个在haproxy中很好实现 可以参考https://dyrnq.com/hadoop-namenode-ha/#%e8%a7%a3%e5%86%b3

dyrnq avatar Jul 05 '24 00:07 dyrnq