You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "GloryAndDream (via GitHub)" <gi...@apache.org> on 2023/04/07 06:31:26 UTC

[GitHub] [apisix] GloryAndDream opened a new issue, #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

GloryAndDream opened a new issue, #9258:
URL: https://github.com/apache/apisix/issues/9258

   ### Description
   
   `apiVersion: apisix.apache.org/v2
   kind: ApisixRoute
   metadata:
     name: service-route
     namespace: dev
   spec:
     http:
       - name: machine-service-app
         match:
           hosts:
             - api-test.xxx.com
           paths:
             - "/machine/*"
             - "/pay/*"
         plugins:
         - name: proxy-rewrite
           enable: true
           config:
             regex_uri: ["^/machine|pay(/|$)(.*)", "/$2"]
         backends:
         - serviceName: machine-service-app
           servicePort: 8001
    `
   
   I want to proxy-rewrite support multiple paths, but even I got regexp correct, it didn't work for both paths:
   
   e.g. regexp is below:
   
   **^/machine|pay(/|$)(.*)**
   
   can match below paths:
   
   **/machine/tests
   /machine
   /machine/
   /pay/testset
   /pay/**
   
   However, when I deploy this configurations, it can only match paths begin with **/machine/*** , not the **/pay/xxx**
   
   Is there a solution or not? 
   
   
   
   ### 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`):
   


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

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


[GitHub] [apisix] kingluo commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "kingluo (via GitHub)" <gi...@apache.org>.
kingluo commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1500396829

   `|` must be quoted with `(`. That's not a bug, it's regex usage issue.
   
   What's your question? I'm really confused.
   
   > However, when I deploy this configurations, it can only match paths begin with /machine/* , not the /pay/xxx
   
   or 
   
   >http://api-test.xxx.com/machine
   >
   >{"error_msg":"404 Route Not Found"}`
   
   Anyways, the regex obeys the pcre regex standard, please change your regex to fit your need.


-- 
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] kingluo commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "kingluo (via GitHub)" <gi...@apache.org>.
kingluo commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1500366151

   What part of the uri do you want to extract? In my code,  I assume you need to get the second part, that is, for `/machine/health`, you need `/health`. If that's not your case, you need to configure the target uri you need for the upstream server. In your output, the request http://api-test.xxx.com/machine/health will be changed to http://api-test.xxx.com/health, and it's obvious it's sent to the controller server, but gets 404 finally.
   Anyways, you need to debug your regexp to fit your need.


-- 
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] GloryAndDream commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "GloryAndDream (via GitHub)" <gi...@apache.org>.
GloryAndDream commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1500376993

   > ```shell
   > "^/(machine|pay)(/.*)", "/$2"
   > ```
   
   Yes, I need to extract second part, but I tried this regexp "^/machine(/.*)", "/$2" , it worked fine, the url **http://api-test.xxx.com/machine/health** is accessible 
   
   it seems the plugin can't handle with **|** 
   


-- 
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] GloryAndDream commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "GloryAndDream (via GitHub)" <gi...@apache.org>.
GloryAndDream commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1500399664

   I need to match below urls:
   e.g. 
   **http://api-test.xxx.com/machine/aaa
   
   http://api-test.xxx.com/pay/bbb**
   
   however, I can't find the correct regexp to get what I need with plugin proxy-rewite
   


-- 
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] kingluo commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "kingluo (via GitHub)" <gi...@apache.org>.
kingluo commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1500169340

   Your regex is wrong.
   
   Example:
   
   ```bash
   curl http://127.0.0.1:9180/apisix/admin/routes/1  \
   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "methods": ["GET"],
       "uri": "/*",
       "plugins": {
           "proxy-rewrite": {
               "regex_uri": ["^/(machine|pay)(/.*)", "/$2"]
           }
       },
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "httpbin.org": 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.

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

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


[GitHub] [apisix] GloryAndDream commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "GloryAndDream (via GitHub)" <gi...@apache.org>.
GloryAndDream commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1580181254

   anyone can help me with correct regex string?


-- 
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] GloryAndDream commented on issue #9258: help request: Can proxy-rewite plugin support multiple path rewrite?

Posted by "GloryAndDream (via GitHub)" <gi...@apache.org>.
GloryAndDream commented on issue #9258:
URL: https://github.com/apache/apisix/issues/9258#issuecomment-1500315036

   
   
   
   > Your regex is wrong.
   > 
   > Example:
   > 
   > ```shell
   > curl http://127.0.0.1:9180/apisix/admin/routes/1  \
   > -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   > {
   >     "methods": ["GET"],
   >     "uri": "/*",
   >     "plugins": {
   >         "proxy-rewrite": {
   >             "regex_uri": ["^/(machine|pay)(/.*)", "/$2"]
   >         }
   >     },
   >     "upstream": {
   >         "type": "roundrobin",
   >         "nodes": {
   >             "httpbin.org": 1
   >         }
   >     }
   > }'
   > ```
   
   I tried you regexp, still not working
   
   
   **http://api-test.xxx.com/machine/health**
   
   ```
   
   Whitelabel Error Page
   This application has no explicit mapping for /error, so you are seeing this as a fallback.
   
   Fri Apr 07 21:56:08 CST 2023
   There was an unexpected error (type=Not Found, status=404).
   ```
   
   
   **http://api-test.xxx.com/machine**
   
   `{"error_msg":"404 Route Not Found"}`
   
   seems only first part of path goes to controller, by the way, the API is built on springboot


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