forget99 commented on issue #9709:
URL: https://github.com/apache/apisix/issues/9709#issuecomment-1605820727

   > > > @forget99 Can you paste the full access log where path is also 
visible? Can you also share the business logic of your `AuthFilter` plugin that 
is running ?
   > > 
   > > 
   > > 
当在配置路由时,只配置了前置插件(ext-plugin-pre-req),并且配置了域名重写,此时通过apisix调用上游服务(https服务,只支持域名访问,不支持ip
 + post)是调用成功的。 `{ "uri": "/test-api/*", "name": "测试api", "desc": "测试api", 
"methods": [ "GET", "POST" ], "plugins": { "ext-plugin-pre-req": { 
"allow_degradation": true, "conf": [ { "name": "AuthFilter", "value": 
"authFilter" } ], "disable": false }, "proxy-rewrite": { "host": "test.com", 
"regex_uri": [ "^/test-api(/|$)(.*)", "/$2" ], "use_real_request_uri_unsafe": 
false } }, "service_id": "1671453424892182530", "labels": { "API_VERSION": "v1" 
}, "status": 1 }`
   > > 此时调用的 access.log 日志信息如下:
   > > 10.19.36.132 - - [25/Jun/2023:09:29:42 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 200 111 0.056 "-" 
"PostmanRuntime/7.29.2" 39.105.180.130:80 200 0.048 
"http://test.com.com/vehicle/info/queryVerifyByVehicleNo";
   > 
   > 10.19.36.132 - - [25/Jun/2023:09:29:43 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 200 111 0.062 "-" 
"PostmanRuntime/7.29.2" 39.105.180.130:80 200 0.052 
"http://test.com.com/vehicle/info/queryVerifyByVehicleNo";
   > 
   > 10.19.36.132 - - [25/Jun/2023:09:29:43 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 200 111 0.053 "-" 
"PostmanRuntime/7.29.2" 39.105.180.130:80 200 0.048 
"http://test.com.com//vehicle/info/queryVerifyByVehicleNo";
   
   > > > @forget99 Can you paste the full access log where path is also 
visible? Can you also share the business logic of your `AuthFilter` plugin that 
is running ?
   > > 
   > > 
   > > 
当在配置路由时,只配置了前置插件(ext-plugin-pre-req),并且配置了域名重写,此时通过apisix调用上游服务(https服务,只支持域名访问,不支持ip
 + post)是调用成功的。 `{ "uri": "/test-api/*", "name": "测试api", "desc": "测试api", 
"methods": [ "GET", "POST" ], "plugins": { "ext-plugin-pre-req": { 
"allow_degradation": true, "conf": [ { "name": "AuthFilter", "value": 
"authFilter" } ], "disable": false }, "proxy-rewrite": { "host": "test.com", 
"regex_uri": [ "^/test-api(/|$)(.*)", "/$2" ], "use_real_request_uri_unsafe": 
false } }, "service_id": "1671453424892182530", "labels": { "API_VERSION": "v1" 
}, "status": 1 }`
   
   > > 此时调用的 access.log 日志信息如下,从日志中可以看出上游服务接口响应200,调用成功:
   > > 10.19.36.132 - - [25/Jun/2023:09:29:42 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 200 111 0.056 "-" 
"PostmanRuntime/7.29.2" 39.105.180.130:80 200 0.048 
"http://test.com.com/vehicle/info/queryVerifyByVehicleNo";
   > 
   > 10.19.36.132 - - [25/Jun/2023:09:29:43 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 200 111 0.062 "-" 
"PostmanRuntime/7.29.2" 39.105.180.130:80 200 0.052 
"http://test.com.com/vehicle/info/queryVerifyByVehicleNo";
   > 
   > 10.19.36.132 - - [25/Jun/2023:09:29:43 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 200 111 0.053 "-" 
"PostmanRuntime/7.29.2" 39.105.180.130:80 200 0.048 
"http://test.com.com//vehicle/info/queryVerifyByVehicleNo";
   
   
   
   
   
当在配置路由时,同时配置了前置插件(ext-plugin-pre-req),后置插件(ext-plugin-post-resp),同时配置了域名重写,此时通过apisix调用上游服务(https服务,只支持域名访问,不支持ip+port)调用不成功,原因可能是后置插件在调用上游服务时,采用的是ip
 + port调用,上游服务的nginx给拦截了。
   
   `{
        "uri": "/test-api/*",
        "name": "测试api",
        "desc": "测试api",
        "methods": ["GET", "POST"],
        "plugins": {
                "ext-plugin-post-resp": {
                        "allow_degradation": false,
                        "conf": [{
                                "name": "AuthFilter",
                                "value": "authFilter"
                        }],
                        "disable": false
                },
                "ext-plugin-pre-req": {
                        "allow_degradation": true,
                        "conf": [{
                                "name": "AuthFilter",
                                "value": "authFilter"
                        }],
                        "disable": false
                },
                "proxy-rewrite": {
                        "host": "test.com",
                        "regex_uri": ["^/test-api(/|$)(.*)", "/$2"],
                        "use_real_request_uri_unsafe": false
                }
        },
        "service_id": "1671453424892182530",
        "labels": {
                "API_VERSION": "v1"
        },
        "status": 1
   }`
   
   
   此时调用的 access.log 日志信息如下,从日志中可以看出上游服务接口响应404,调用失败:
   10.19.36.132 - - [25/Jun/2023:09:54:40 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 404 157 0.098 "-" 
"PostmanRuntime/7.29.2" - - - 
"http://test.com.com//vehicle/info/queryVerifyByVehicleNo";
   
   10.19.36.132 - - [25/Jun/2023:09:54:40 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 404 157 0.076 "-" 
"PostmanRuntime/7.29.2" - - - 
"http://test.com.com//vehicle/info/queryVerifyByVehicleNo";
   
   10.19.36.132 - - [25/Jun/2023:09:54:41 +0800] 192.17.101.106:9080 "POST 
/test-api/vehicle/info/queryVerifyByVehicleNo HTTP/1.1" 404 157 0.073 "-" 
"PostmanRuntime/7.29.2" - - - 
"http://test.com.com//vehicle/info/queryVerifyByVehicleNo";
   
   
   
   
   
   
   
   
   
   AuthFilter过滤器逻辑如下:
   `
   @Component
   public class AuthFilter implements PluginFilter {
   
       private final Logger logger = LoggerFactory.getLogger(AuthFilter.class);
   
       @Override
       public String name() {
           return "AuthFilter";
       }
   
       @Override
       public void filter(HttpRequest request, HttpResponse response, 
PluginFilterChain chain) {
           logger.info("【进入前置拦截过滤器】");
           // 在前置插件中获取接口的请求相关信息
   
   
   
           chain.filter(request, response);
       }
   
       @Override
       public void postFilter(PostRequest request, PostResponse response, 
PluginFilterChain chain) {
           logger.info("【进入后置拦截过滤器】");
           // 在后置插件中获取到上游服务的响应结果,但是这里在调用上游服务时应该把域名调用转为了ip + 
port调用,上游服务的nginx给拦截了
   
           chain.postFilter(request, response);
       }
   
       @Override
       public List<String> requiredVars() {
           List<String> vars = new ArrayList<>();
           vars.add("remote_addr");
           vars.add("server_port");
           vars.add("request_id");
           return vars;
       }
   
       @Override
       public Boolean requiredBody() {
           return true;
       }
   
       @Override
       public Boolean requiredRespBody() {
           return true;
       }
   }
   `
   
   请技术老师帮忙看下,感谢!!!
   
   
   
   
   
   
   
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to