3

It is possible to configure nginx to output in error log specified part of files path? F.e:

2017/09/16 19:59:28 [error] 10656#10656: *1702 open() "/home/user/www/favicon.ico" failed (2: No such file or directory), client: 256.256.256.256, server: example.com, request: "GET /favicon.ico HTTP/1.1", host: "example.com", referrer: "http://example.com/"

The user has chroot on "/home/user/", so "favicon.ico" for this user has this path: "/www/favicon.ico". Real path of file is little bit confusing.

1

This error message is being output by the PHP FastCGI server. To make it use paths relative to the chroot, run the FastCGI server in the chroot. (This will also sandbox the PHP scripts, which is probably a good thing!)

  • this output is from nginx. because: 2017/09/16 19:59:28 [error] 10656#10656: *1702 open() "/home/user/www/favicon.ico" – aabaev Sep 17 '17 at 8:36
  • That's a completely different error from the one you included in your question. – duskwuff Sep 17 '17 at 8:48
  • Es, but all errors logged by nginx. I edited my question to exclude FastCGI focus – aabaev Sep 17 '17 at 10:45
0

Rather than report missing pathnames in the error log, you could report missing URIs in the access log.

For example:

try_files $uri $uri/ =404;

The above statement should cause nginx to behave almost identically to its default behaviour, except when logging missing URIs.

See this document for more.

0

If some one will have similar issue this is how i solve it (it can't be marked as the right question, because this is a workaround):

inotifywait -m -e modify --format "%w%f" /home/user/log/nginx/example.com.error.log | while read f; do if [[ $(grep "/home/user" $f | wc -c)  != 0 ]] ; then sed 's/\/home\/user//g' $f > $f\t ; cat $f\t > $f ; fi done

Where inotifywait (inotify-tools package) is file watcher in monitor mode which is trigger when modification of file are made:

inotifywait -m -e modify --format "%w%f"

then, in a while loop we need to run 2 commands, but first check if the new modification of file contains specific string, to avoid stacking in infinite loop:

if [[ $(grep "/home/user" $f | wc -c) != 0 ]]

If result of command grep "/home/user" $f passed in wc -c which is mean length of string != 0 then modificate file by replaced all /home/user to the 0 length string //, save the output in the temp file and finaly write this output from temp file in the nginx error log file cat $f\t > $f

sed 's/\/home\/user//g' $f > $f\t; cat $f\t > $f;done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.