E
E
ekholdthero2020-09-11 15:45:18
linux
ekholdthero, 2020-09-11 15:45:18

How to parse nginx log to static?

You need to parse the nginx log and get all the file extensions that are requested

cat access.log | awk '{print $8}' | rev | cut -d'.' -f1 | rev | sort | uniq -c | sort -rn

The command displays extensions but with it a lot of unnecessary garbage, how to optimize to display only extensions?
It is required to leave only the list of extensions and remove all unnecessary
881781 jpg
 159161 png
  96670 html
  94454 webp
  70508 js
  68654 ico
  55866 css
  48728 jpeg
  35943 1
  27878 php
  12441 htm
  12270 2
   9556 gif
   6468 4-wp
   6258 woff?12
   5655 /?utm_source=adbless&utm_medium=cpm&utm_campaign=3126
   5595 3
   5528 /
   5388 /?utm_source=onixz
   4951 xml
   4321 woff?13
   4068 txt

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vreitech, 2020-09-11
@fzfx

just add the appropriate code that will parse the strings to see if they are extensions or not.
since you didn't specify which of these are extensions and which are not, I will rely on my experience.
for example like this:

cat access.log | awk '{print $8}' | rev | cut -d'.' -f1 | rev | perl -pe 's/\?.*//;s/^\/$//' | sort | uniq -c | sort -rn

K
ky0, 2020-09-12
@ky0

Add a static location (directly listing the extensions, for example) that would log requests to a separate file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question