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/06/14 07:18:29 UTC

[GitHub] [apisix] xyz2b opened a new issue #4417: request help: http-logger plugin log_format `$host` value is wrong

xyz2b opened a new issue #4417:
URL: https://github.com/apache/apisix/issues/4417


   ### Issue description
   request help: http-logger plugin log_format `$host` value is wrong.
   The `$host` should be the host requested by the client, but the local address of apisix obtained in http-logger.
   
   http-logger log_format config
   ```shell
   {
     "count": "1",
     "node": {
       "key": "/apisix/plugin_metadata/http-logger",
       "value": {
         "log_format": {
           "route_id": "$route_id",
           "route_name": "$route_name",
           "uri": "$uri",
           "http_x_forwarded_for": "$http_x_forwarded_for",
           "request_method": "$request_method",
           "upstream_addr": "$upstream_addr",
           "request_time": "$request_time",
           "consumer_name": "$consumer_name",
           "upstream_response_time": "$upstream_response_time",
           "request_body": "$request_body",
           "protocol": "$server_protocol",
           "bytes_sent": "$bytes_sent",
           "http_user_agent": "$http_user_agent",
           "status": "$status",
           "@source": "$server_addr",
           "http_referrer": "$http_referer",
           "upstream_status": "$upstream_status",
           "@timestamp": "$time_iso8601",
           "host": "$host",
           "service_id": "$service_id",
           "remote_user": "$remote_user",
           "body_bytes_sent": "$body_bytes_sent",
           "remote_addr": "$remote_addr",
           "server": "$server_name",
           "upstream_connect_time": "$upstream_connect_time",
           "request_uri": "$request_uri",
           "content_type": "$content_type",
           "port": "$server_port",
           "service_name": "$service_name"
         }
       }
     },
     "action": "get"
   }
   ```
   
   elk log
   ```shell
   {
     "_source": {
       "route_name": "aomp-web-websocket",
       "request_time": 0.08,
       "port": "9080",
       "upstream_connect_time": 0,
       "@timestamp": "2021-06-11T10:28:49.000Z",
       "host": "10.107.97.180",
       .....
       }
   }
   ```
   
   ### Environment
   
   Request help without environment information will be ignored or closed.
   
   * apisix version (cmd: `apisix version`): 2.6
   * OS (cmd: `uname -a`): 
   ```shell
   [app@VM_97_180_centos apisix]$ uname -a
   Linux VM_97_180_centos 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
   ```
   * OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   ```shell
   [app@VM_97_180_centos apisix]$ openresty -V                                                               
   nginx version: openresty/1.19.3.1
   built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
   built with OpenSSL 1.1.1k  25 Mar 2021
   TLS SNI support enabled
   configure arguments: --prefix=/data/app/openresty/nginx --with-debug --with-cc-opt='-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.19 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../ngx_stream_lua-0.0.9 --with-ld-opt=-Wl,-rpath,/data/app/openresty/luajit/lib --user=app --group=apps --add-module=/data/backup/openresty-1.19.3.1/../mod_dubbo --add-module=/data/backup/openresty-1.19.3.1/../ngx_multi_upstream_module --
 add-module=/data/backup/openresty-1.19.3.1/../apisix-nginx-module --with-poll_module --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-openssl=/data/backup/openresty-1.19.3.1/../openssl-OpenSSL_1_1_1k --with-openssl-opt=-g --with-stream --with-http_ssl_module
   ```
   * etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   ```shell
   [app@VM_97_180_centos apisix]$ curl --cert ./ssl/etcd.pem --key ./ssl/etcd-key.pem --cacert ./ssl/ca.pem -i https://etcd01.apisix.webank.com:2379/version
   
   {"etcdserver":"3.4.16","etcdcluster":"3.4.0"}
   ```
   * apisix-dashboard version, if have: 2.6.1
   * luarocks version, if the issue is about installation (cmd: `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.

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



[GitHub] [apisix] xyz2b commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   @tokers Hello.
   If the Host header of the client request is the local address of APISIX, how can APISIX route to the correct upstream service? Isn't APISIX based on Host to determine which routing rule to follow?


-- 
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] xyz2b commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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






-- 
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] Yiyiyimu closed issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   


-- 
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] xyz2b commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   I found the problem, it's a logstash problem, sorry, thank you all. @tokers @Yiyiyimu 


-- 
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] Yiyiyimu removed a comment on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

Posted by GitBox <gi...@apache.org>.
Yiyiyimu removed a comment on issue #4417:
URL: https://github.com/apache/apisix/issues/4417#issuecomment-859980496


   Ah I see, would fix it later. Thanks for remind @xyz2b 


-- 
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] xyz2b commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   client request
   ![企业微信截图_16236806921969](https://user-images.githubusercontent.com/48942966/121909437-7a756300-cd60-11eb-9d24-6c024219b956.png)
   
   apisix route config
   ```shell
   {
     "uris": [
       "/*"
     ],
     "name": "aomp-web",
     "methods": [
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE"
     ],
     "hosts": [
       "sit.aomp.weoa.com"
     ],
     "remote_addrs": [
       "0.0.0.0/0"
     ],
     "service_id": "357764672524387208",
     "labels": {
       "API_VERSION": "v1",
       "env": "sit",
       "subsystem": "aomp-web",
       "system": "aomp"
     },
     "status": 1
   }
   ```
   
   apisix upstream config
   ```shell
   {
     "name": "aomp-web",
     "desc": "sit",
     "upstream": {
       "nodes": [
         {
           "host": "172.16.144.101",
           "port": 8086,
           "weight": 50
         },
         {
           "host": "172.16.144.104",
           "port": 8086,
           "weight": 50
         }
       ],
       "timeout": {
         "connect": 600,
         "read": 600,
         "send": 600
       },
       "type": "roundrobin",
       "checks": {
         "active": {
           "concurrency": 10,
           "healthy": {
             "http_statuses": [
               200,
               302,
               301
             ],
             "interval": 1,
             "successes": 2
           },
           "host": "sit.aomp.weoa.com",
           "http_path": "/",
           "port": 8086,
           "timeout": 10,
           "type": "http",
           "unhealthy": {
             "http_failures": 5,
             "http_statuses": [
               429,
               404,
               500,
               501,
               502,
               503,
               504,
               505
             ],
             "interval": 1,
             "tcp_Failures": 2,
             "timeouts": 3
           }
         }
       },
       "scheme": "http",
       "pass_host": "pass"
     }
   }
   ```
   
   apisix access log in local file
   ```shell
   {"@timestamp":"2021-06-14T22:18:41+08:00","@source":"10.107.97.180","remote_addr":"10.36.32.54","remote_user":"","bytes_sent":"1363","request_time":"0.089","status":"200","host":"sit.aomp.
   weoa.com","uri":"/login/","server":"_","port":"9080","upstream_connect_time":"0.038","protocol":"HTTP/1.1","upstream_status":"200","request_uri":"/login/?next=/","content_type":"","request
   _method":"GET","body_bytes_sent":"1189","http_x_forwarded_for":"10.36.32.54","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0
   .4389.90 Safari/537.36","upstream_response_time":"0.089","upstream_addr":"172.16.144.101:8086"}
   ```
   
   apisix access log in elastic
   ```shell
   {
     "_index": "nginx-log-2021.06.14",
     "_type": "doc",
     "_id": "zvrjCnoBS4SRzeIbwqcK",
     "_version": 1,
     "_score": null,
     "_source": {
       "route_name": "aomp-web",
       "status": "200",
       "service_id": "357764672524387208",
       "upstream_response_time": 0.089,
       "bytes_sent": 1363,
       "@source": "10.107.97.180",
       "@version": "1",
       "service_name": "aomp-web",
       "request_time": 0.089,
       "port": "9080",
       "upstream_connect_time": 0.038,
       "@timestamp": "2021-06-14T14:18:41.000Z",
       "host": "10.107.97.180",
       "upstream_addr": "172.16.144.101:8086",
       "http_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
       "headers": {
         "request_path": "/log?",
         "content_length": "15554",
         "http_version": "HTTP/1.1",
         "http_host": "10.107.97.123",
         "content_type": "application/json",
         "http_user_agent": "lua-resty-http/0.14 (Lua) ngx_lua/10019",
         "http_accept": null,
         "request_method": "POST"
       },
       "request_method": "GET",
       "server": "_",
       "route_id": "357768367756542856",
       "uri": "/login/",
       "body_bytes_sent": 1189,
       "http_x_forwarded_for": "10.36.32.54",
       "upstream_status": "200",
       "protocol": "HTTP/1.1",
       "request_uri": "/login/?next=/",
       "remote_addr": "10.36.32.54"
     },
     "fields": {
       "@timestamp": [
         "2021-06-14T14:18:41.000Z"
       ]
     },
     "highlight": {
       "remote_addr": [
         "@kibana-highlighted-field@10.36.32.54@/kibana-highlighted-field@"
       ],
       "route_name": [
         "@kibana-highlighted-field@aomp@/kibana-highlighted-field@-@kibana-highlighted-field@web@/kibana-highlighted-field@"
       ]
     },
     "sort": [
       1623680321000
     ]
   }
   ```


-- 
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] tokers commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   @xyz2b 
   This is the description of `$host` (quoted from nginx document):
   
   > in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request
   
   You should check whether there are some requests which use the full URI in the request line, or, the Host header itself is the IP address of APISIX instance.


-- 
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] tokers commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   > @tokers Hello.
   > 
   > If the Host header of the client request is the local address of APISIX, how can APISIX route to the correct upstream service? Isn't APISIX based on Host to determine which routing rule to follow?
   
   I cannot answer this question, you even didn't paste the related route.


-- 
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] xyz2b commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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


   @tokers 
   The host of the log in the local log file is not the local address of apisix, is the domain name requested by the client.
   But the host field reported by http-logger to elastic is indeed the local address of apisix.


-- 
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] Yiyiyimu commented on issue #4417: request help: http-logger plugin log_format `$host` value is wrong

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






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