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 2020/08/03 10:14:52 UTC

[GitHub] [apisix] purelind opened a new issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

purelind opened a new issue #1975:
URL: https://github.com/apache/apisix/issues/1975


   ### Issue description
   
   How to use upstream chash implement looking a specific node ip based on url head value.
   example
   ```nginx
   map $HEAD_userid $group {
       1   cluster1;
       2   cluster2;
       default   cluster1;
   }
   
   upstream cluster {
       server   a.iresty.com;
   }
   
   upstream cluster2 {
      server b.iresty.com
   }
   
   server {
       location / {
           proxy_pass    http://${group};
       }
   
   }
   
   ###
   
   url with HAED userid=1   http://127.0.0.1:9080/  -->  http://a.iresty.com/
   url with HEAD userid=2   http://127.0.0.1:9080/  -->  http://b.iresty.com/
   
   ```
   
   
   upstream chash doc describe some usage about type chash, it say that looking specify node ip base on key && hash_on parameters. 
   
   ![Screenshot 2020-08-03 at 17 42 26](https://user-images.githubusercontent.com/16618216/89170582-6eead480-d5b2-11ea-91b6-a9a892dad643.png)
   
   
   I have read a closed issuse about this which claim that upstream chash could figure out this problem.   #1488 
   
   Coud you explain more detail for me about how to apply this in apisix upstream
   
   Thank you!
   
   ### Environment
   
   * apisix version (cmd: `apisix version`): 1.4
   * OS: ubuntu18.04.2
   


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

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



[GitHub] [apisix] membphis commented on issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

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


   @purelind you can create two routes, different route use different upstream node


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

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



[GitHub] [apisix] purelind closed issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

Posted by GitBox <gi...@apache.org>.
purelind closed issue #1975:
URL: https://github.com/apache/apisix/issues/1975


   


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

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



[GitHub] [apisix] membphis commented on issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

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


   please take a look at this test case: https://github.com/apache/apisix/blob/master/t/admin/upstream.t#L1186
   
   if you have any questions, please let us know.


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

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



[GitHub] [apisix] purelind commented on issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

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


   Thanks a lot!  Two different routes with vars figureout my problem exactly.


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

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



[GitHub] [apisix] purelind commented on issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

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


   @membphis  Please take a look, thank you!


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

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



[GitHub] [apisix] purelind commented on issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

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


   I have read this test case. 
   
   It means that apisix will chose upstream node ip base on the result of hash on custom_head value, but which node ip been selected is depend on hash_on algorithm. On the other way, it mean we are not able to select specific node ip in my way.    
   
   ```nignx
   current useage:
   hash_on type is header, key is content-type. node ip is depend on result of hash of header_content-type
   {
       "uri": "/hash_on_header",
       "upstream": {
           "key": "content-type",
           "type ": "chash",
           "hash_on ": "header",
           "nodes ": {
               "127.0.0.1:1980": 1,
               "127.0.0.1:1981": 1
           }
       }
   }
   
   what i want:
   hash_on type is header, key is custom head User-PhoneNumber,  User-PhoneNumber=123456789 is special.
   {
       "uri": "/hash_on_header",
       "upstream": {
           "key": "user-phonenumber=123456789",
           "type ": "chash",
           "hash_on ": "header",
           "nodes ": {
               "127.0.0.1:1980": 1,  # user-phonenumber=123456789
               "127.0.0.1:1981": 1  # user-phtonenumber != 123456789
           }
       }
   }
   ```
   
   thank you for your response.


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

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



[GitHub] [apisix] purelind commented on issue #1975: request help: How to redirect url to specific node ip base on url head value with upstream chash?

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


   ```nginx
   route1
   {
       "uri": "/test",
       "hosts": ["*.iresty.com"],
       "methods": ["PUT", "GET"],
       "name": "指定路由至特定upstream",
       "vars": [
           ["http_phonenumber", "~=", 123456789]
       ],
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
   }
   
   route2
   {
       "uri": "/test",
       "hosts": ["*.iresty.com"],
       "methods": ["PUT", "GET"],
       "name": "指定路由至特定upstream",
       "vars": [
           ["http_phonenumber", "==", 123456789]
       ],
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
   }
   ```


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

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