1

How can i get all 404 errors from all the sites into one log? I only know how to do it on one domain and only when i change the default 404 page.

Here is how i did it on one domain

    error_page 404 /404.html;
    location = /404.html {
            root /home/awesomename;
            access_log /home/custom_logs/404.log;
            internal;
    }

Is there a way to do it without changing anything else?

1

The if parameter (1.7.0+) enables conditional logging. A request will not be logged if the condition evaluates to “0” or an empty string. In the following example, the requests with response codes 4xx will be logged:

map $status $loggable {
    ~^[4]   1;
    default 0;
}

access_log /path/to/access.log combined if=$loggable;
2
  • thanks for your answer @nomadic but this will log only the errors right? – Bill May 24 '17 at 10:08
  • yes, default 0 (false) – Nomadic May 25 '17 at 10:23
0

You need to use the same thing on all site configurations. You can put the location block into a separate configuration file and then use include to include it in all your virtual hosts.

2
  • i can use the same file for every domain or i need to make a new file for every domain? and does it work without changing the error page? in the example that i used i was changing the error page on other domains i have nodejs handling the page and i dont want to change that – Bill Apr 23 '17 at 21:20
  • You can use the same file on every domain and include the file in every domain's configuration file. – Tero Kilkanen Apr 24 '17 at 10:06

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.