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/10/29 01:28:43 UTC

[GitHub] [apisix] amazing-gao opened a new issue #5363: bug: configure upstream `Hostname` does not work

amazing-gao opened a new issue #5363:
URL: https://github.com/apache/apisix/issues/5363


   ### Issue description
   
   I configure upstream `Hostname` to `Use the domain or IP from Node List`, but upstream received hostname still be `Keep the same Host from client request`.
   
   Proxy request log show it uses `host: "10.2.130.145:9080"`, not my upstream node IP.
   
   ```
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] balancer.lua:349: run(): proxy request to 10.51.167.92:7007 while connecting to upstream, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   ```
   
   My upstream deployed on k8s and has an envoy gateway. if HTTP  `host`  is wrong, will get 404.
   
   apisix: `10.2.130.145:9080`
   upstream: `10.51.167.92:7007`
   
   
   
   
   ### Environment
   
   - apisix version (cmd: `apisix version`): `2.10.0`
   - OS (cmd: `uname -a`): `Linux c0fff832da83 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 Linux`
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): `nginx version: openresty/1.19.3.1`
   - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): `3.4.9`
   - apisix-dashboard version, if have:  `2.9.0`
   - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks --version`): `3.7.0`
   
   
   ### Steps to reproduce
   
   1. upstream config: 
   ```json
   {
     "nodes": [
       {
         "host": "10.51.167.92",
         "port": 7007,
         "weight": 1
       }
     ],
     "retries": 1,
     "timeout": {
       "connect": 6,
       "send": 6,
       "read": 6
     },
     "type": "roundrobin",
     "scheme": "http",
     "pass_host": "node",
     "name": "yyyyy",
     "keepalive_pool": {
       "idle_timeout": 60,
       "requests": 1000,
       "size": 320
     }
   }
   ```
   
   2. route config: 
   ```json
   {
     "uri": "/*",
     "name": "xxxx",
     "upstream_id": "378825999736898241",
     "status": 1
   }
   ```
   
   3. curl apisix gateway get 404
   ```sh
   curl -v http://10.2.130.145:9080/user/info\?test\=abc
   *   Trying 10.2.130.145...
   * TCP_NODELAY set
   * Connected to 10.2.130.145 (10.2.130.145) port 9080 (#0)
   > GET /user/info?test=abc HTTP/1.1
   > Host: 10.2.130.145:9080
   > User-Agent: curl/7.64.1
   > Accept: */*
   >
   < HTTP/1.1 404 Not Found
   < Content-Length: 0
   < Connection: keep-alive
   < date: Fri, 29 Oct 2021 01:09:37 GMT
   < Server: APISIX/2.10.0
   <
   * Connection #0 to host 10.2.130.145 left intact
   * Closing connection 0
   ```
   
   ### Actual result
   
   curl apisix gateway get 404
   
   ### Error log
   
   1. access.log
   ```
   10.2.230.47 - - [29/Oct/2021:01:11:21 +0000] 10.2.130.145:9080 "GET /user/info?test=abc HTTP/1.1" 404 0 0.003 "-" "curl/7.64.1" 10.51.167.92:7007 404 0.008 "http://10.51.167.92"
   ```
   
   2. error.log
   ```
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] radixtree.lua:488: compare_param(): pcre pat: \/((.|\n)*), client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] init.lua:392: http_access_phase(): matched route: {"clean_handlers":{},"has_domain":false,"value":{"name":"yyyyyyy","create_time":1635327783,"priority":0,"status":1,"id":"378826490520797889","upstream_id":"378825999736898241","uri":"\/*","update_time":1635399767},"modifiedIndex":1355,"update_count":0,"orig_modifiedIndex":1355,"key":"\/apisix\/routes\/378826490520797889","createdIndex":52}, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] init.lua:305: get_upstream_by_id(): parsed upstream: {"has_domain":false,"value":{"name":"xxx","nodes_ref":[{"host":"10.51.167.92","weight":1,"priority":0,"port":7007}],"nodes":"table: 0x7f6a6b687b68","id":"378825999736898241","hash_on":"vars","original_nodes":[{"host":"10.51.167.92","weight":1,"port":7007}],"update_time":1635407092,"pass_host":"node","create_time":1635327491,"retries":1,"parent":{"has_domain":false,"value":"table: 0x7f6a664da830","modifiedIndex":1481,"clean_handlers":{},"key":"\/apisix\/upstreams\/378825999736898241","createdIndex":44},"scheme":"http","type":"roundrobin","keepalive_pool":{"requests":1000,"idle_timeout":60,"size":320},"timeout":{"connect":6,"send":6,"read":6}},"modifiedIndex":1481,"clean_handlers":"table: 0x7f6a66a62dc8","key":"\/apisix\/upstreams\/378825999736898241","createdIndex":44}, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] balancer.lua:183: pick_server(): route: {"clean_handlers":{},"has_domain":false,"value":{"name":"yyyyyyy","create_time":1635327783,"priority":0,"status":1,"id":"378826490520797889","upstream_id":"378825999736898241","uri":"\/*","update_time":1635399767},"modifiedIndex":1355,"update_count":0,"orig_modifiedIndex":1355,"key":"\/apisix\/routes\/378826490520797889","createdIndex":52}, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] balancer.lua:184: pick_server(): ctx: {"curr_req_matched":{":ext":"user\/info","_method":"GET","_path":"\/*"},"conf_type":"route","matched_upstream":{"name":"xxx","nodes_ref":[{"host":"10.51.167.92","weight":1,"priority":0,"port":7007}],"nodes":"table: 0x7f6a6b687b68","id":"378825999736898241","hash_on":"vars","original_nodes":[{"host":"10.51.167.92","weight":1,"port":7007}],"update_time":1635407092,"pass_host":"node","create_time":1635327491,"retries":1,"parent":{"has_domain":false,"value":"table: 0x7f6a664da830","modifiedIndex":1481,"clean_handlers":{},"key":"\/apisix\/upstreams\/378825999736898241","createdIndex":44},"scheme":"http","type":"roundrobin","keepalive_pool":{"requests":1000,"idle_timeout":60,"size":320},"timeout":{"connect":6,"send":6,"read":6}},"conf_version":1355,"var":{"_request":"cdata<void *>: 0x7f6a66939320","_cache":{"host":"10.2.130.145","upstream_scheme":"http","request_method":"GET","uri":"\/user\/info","rem
 ote_addr":"10.2.230.47"}},"upstream_conf":"table: 0x7f6a664da830","route_id":"378826490520797889","route_name":"yyyyyyy","plugins":{},"matched_route":{"clean_handlers":{},"has_domain":false,"value":{"name":"yyyyyyy","create_time":1635327783,"priority":0,"status":1,"id":"378826490520797889","upstream_id":"378825999736898241","uri":"\/*","update_time":1635399767},"modifiedIndex":1355,"update_count":0,"orig_modifiedIndex":1355,"key":"\/apisix\/routes\/378826490520797889","createdIndex":52},"upstream_key":"roundrobin#upstream_table: 0x7f6a664da830","upstream_healthcheck_parent":"table: 0x7f6a6b68aa10","upstream_version":1355,"upstream_scheme":"http","conf_id":"378826490520797889"}, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] init.lua:532: http_access_phase(): stash ngx ctx: 1, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] balancer.lua:349: run(): proxy request to 10.51.167.92:7007 while connecting to upstream, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", host: "10.2.130.145:9080"
   2021/10/29 01:11:21 [info] 44#44: *5416719 [lua] init.lua:548: fetch_ctx(): fetch ngx ctx: 1 while reading response header from upstream, client: 10.2.230.47, server: _, request: "GET /user/info?test=abc HTTP/1.1", upstream: "http://10.51.167.92:7007/user/info?test=abc", host: "10.2.130.145:9080"
   ```
   
   ### Expected result
   
   should response http status code 200 and data of my backend.


-- 
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



[GitHub] [apisix] tzssangglass commented on issue #5363: bug: configure upstream `Hostname` does not work

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #5363:
URL: https://github.com/apache/apisix/issues/5363#issuecomment-954412031


   > Proxy request log show it uses `host: "10.2.130.145:9080"`, not my upstream node IP.
   
   This is the expected behavior, since the host in client's request is `10.2.130.145:9080`, see:
   
   > ```shell
   > *   Trying 10.2.130.145...
   > * TCP_NODELAY set
   > * Connected to 10.2.130.145 (10.2.130.145) port 9080 (#0)
   > > GET /user/info?test=abc HTTP/1.1
   > > Host: 10.2.130.145:9080
   > > User-Agent: curl/7.64.1
   > > Accept: */*
   > ```
   
   
   you need to use `proxy-rewrite` plugin to rewrite the host.


-- 
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