ederparaiso commented on issue #8387:
URL: https://github.com/apache/apisix/issues/8387#issuecomment-1327937707

   Excellent, I'll provide my steps. Ah, sorry about host confusion on curl. It 
was a ctrl-c ctrl-v error when I copied curl command from slack chat. 
   
   **Some system infos:**
   
   ```sh
   $ hostnamectl
   Operating System: Ubuntu 20.04.5 LTS
             Kernel: Linux 5.15.0-53-generic
       Architecture: x86-64
   
   $ docker --version
   Docker version 20.10.21, build baeda1f
   
   $ docker-compose --version
   docker-compose version 1.29.2, build 5becea4c
   ```
   
   **Step by step**
   (I used the last provided file samples as you recommended. Also I pushed 
them to a public repo here https://github.com/ederparaiso/apisix-log-test
   
   start environment
   ```sh
   $ docker-compose up
   $ docker ps
   CONTAINER ID   IMAGE                                 COMMAND                 
 CREATED          STATUS          PORTS                                         
                                                                                
                                                                   NAMES
   0c219c343ebe   apache/apisix:3.0.0-debian            "/docker-entrypoint.…"  
 10 minutes ago   Up 10 minutes   0.0.0.0:9080->9080/tcp, :::9080->9080/tcp, 
0.0.0.0:9091-9092->9091-9092/tcp, :::9091-9092->9091-9092/tcp, 
0.0.0.0:9180->9180/tcp, :::9180->9180/tcp, 0.0.0.0:9443->9443/tcp, 
:::9443->9443/tcp   apisix-log-test_apisix_1
   7a496f39b341   bitnami/etcd:3.4.15                   "/opt/bitnami/script…"  
 10 minutes ago   Up 10 minutes   0.0.0.0:2379->2379/tcp, :::2379->2379/tcp, 
2380/tcp                                                                        
                                                                      
apisix-log-test_etcd_1
   edb7a836faff   apache/apisix-dashboard:2.13-alpine   "/usr/local/apisix-d…"  
 10 minutes ago   Up 10 minutes   0.0.0.0:9000->9000/tcp, :::9000->9000/tcp     
                                                                                
                                                                   
apisix-log-test_apisix-dashboard_1
   ```
   
   check route does not exists
   ```sh
   $ curl -i http://127.0.0.1:9080/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8
   HTTP/1.1 404 Not Found
   Date: Fri, 25 Nov 2022 23:43:33 GMT
   Content-Type: text/plain; charset=utf-8
   Transfer-Encoding: chunked
   Connection: keep-alive
   Server: APISIX/3.0.0
   
   {"error_msg":"404 Route Not Found"}
   ```
   
   create route
   ```
   $ curl -i -X POST \
   >    -H "X-API-KEY:edd1c9f034335f136f87ad84b625c8f1" \
   >    -H "Content-Type:application/json" \
   >    -d \
   > '{
   >   "uri": "/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8",
   >   "name": "test",
   >   "plugins": {
   >     "file-logger": {
   >       "path": "logs/file.log"
   >     }
   >   },
   >   "upstream": {
   >     "nodes": [
   >       {
   >         "host": "run.mocky.io",
   >         "port": 443,
   >         "weight": 1
   >       }
   >     ],
   >     "type": "roundrobin",
   >     "hash_on": "vars",
   >     "scheme": "https",
   >     "pass_host": "pass"
   >   },
   >   "status": 1
   > }' \
   >  'http://127.0.0.1:9180/apisix/admin/routes'
   HTTP/1.1 201 Created
   Date: Fri, 25 Nov 2022 23:46:40 GMT
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   Server: APISIX/3.0.0
   Access-Control-Allow-Origin: *
   Access-Control-Allow-Credentials: true
   Access-Control-Expose-Headers: *
   Access-Control-Max-Age: 3600
   X-API-VERSION: v3
   
   
{"key":"\/apisix\/routes\/00000000000000000046","value":{"status":1,"name":"test","create_time":1669420000,"priority":0,"update_time":1669420000,"plugins":{"file-logger":{"path":"logs\/file.log"}},"uri":"\/v3\/bc8fdfcd-0392-49fa-8520-c8644d1688c8","id":"00000000000000000046","upstream":{"hash_on":"vars","pass_host":"pass","scheme":"https","nodes":[{"port":443,"priority":0,"host":"run.mocky.io","weight":1}],"type":"roundrobin"}}}
   ```
   
   try to consume (without host header)
   ```sh
   $ curl -i http://127.0.0.1:9080/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8
   HTTP/1.1 404 Not Found
   Content-Type: text/html; charset=utf-8
   Transfer-Encoding: chunked
   Connection: keep-alive
   Cache-Control: no-cache
   X-CleverCloudUpgrade: true
   Server: APISIX/3.0.0
   
   <!DOCTYPE HTML>
   <html lang="en">
   omited...
   ```
   
   adding host header **without any changes on route config**
   ```
   $ curl -i http://127.0.0.1:9080/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8 -H 
"Host: run.mocky.io"
   HTTP/1.1 200 OK
   Content-Type: application/json; charset=UTF-8
   Content-Length: 16
   Connection: keep-alive
   Date: Fri, 25 Nov 2022 23:50:13 GMT
   Sozu-Id: 01GJRK5RZRFKEWGBDRREXFDE0Q
   Server: APISIX/3.0.0
   
   {"result": "ok"}
   ```
   
   lookup for file.log
   ```sh
   $ ls -l apisix_log/
   total 60
   -rw-r--r-- 1 root root  1802 nov 25 20:50 access.log
   -rw-r--r-- 1 root root 50685 nov 25 20:50 error.log
   -rw-r--r-- 1 root root     2 nov 25 20:30 nginx.pid
   ```
   
   check logs
   ```sh
   $ cat apisix_log/access.log
   172.25.0.1 - - [25/Nov/2022:23:48:14 +0000] 127.0.0.1:9080 "GET 
/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8 HTTP/1.1" 404 1436 1.613 "-" 
"curl/7.68.0" 185.42.117.108:443 404 1.583 "https://127.0.0.1:9080";
   172.25.0.1 - - [25/Nov/2022:23:50:14 +0000] run.mocky.io "GET 
/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8 HTTP/1.1" 200 16 1.151 "-" 
"curl/7.68.0" 46.252.181.103:443 200 1.127 "https://run.mocky.io";
   ```
   
   lookup for errors
   ```sh
   $ cat apisix_log/error.log | grep error
   2022/11/25 23:50:14 [error] 53#53: *138861 [lua] file-logger.lua:117: 
write_file_data(): failed to open file: logs/file.log, error info: 
logs/file.log: Permission denied while logging request, client: 172.25.0.1, 
server: _, request: "GET /v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8 HTTP/1.1", 
upstream: "https://46.252.181.103:443/v3/bc8fdfcd-0392-49fa-8520-c8644d1688c8";, 
host: "run.mocky.io"
   ```
   
   check apisix routes
   ```sh
   $ curl -i -H "X-API-KEY:edd1c9f034335f136f87ad84b625c8f1" 
'http://127.0.0.1:9180/apisix/admin/routes' 
   HTTP/1.1 200 OK
   Date: Sat, 26 Nov 2022 00:13:16 GMT
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   Server: APISIX/3.0.0
   Access-Control-Allow-Origin: *
   Access-Control-Allow-Credentials: true
   Access-Control-Expose-Headers: *
   Access-Control-Max-Age: 3600
   X-API-VERSION: v3
   
   
{"total":1,"list":[{"modifiedIndex":47,"createdIndex":47,"key":"\/apisix\/routes\/00000000000000000046","value":{"status":1,"name":"test","create_time":1669420000,"priority":0,"update_time":1669420000,"plugins":{"file-logger":{"path":"logs\/file.log"}},"upstream":{"hash_on":"vars","pass_host":"pass","scheme":"https","nodes":[{"port":443,"priority":0,"host":"run.mocky.io","weight":1}],"type":"roundrobin"},"id":"00000000000000000046","uri":"\/v3\/bc8fdfcd-0392-49fa-8520-c8644d1688c8"}}]}
   ```
   


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