4

Every single time I set up a new httpd installation, I struggle with the initial  VirtualHost / mod_proxy_fcgi / etc. configuration.

When I set up my virtual hosts and get a 404, I always turn to the logs, only to find:

  • access_log:

    ::1 - - [13/Sep/2019:21:33:57 +0200] "GET /phpinfo.php HTTP/1.1" 404 196
    

    That is, only that a 404 happened.

  • error_log:

    ...
    [Fri Sep 13 21:33:55.009444 2019] [mpm_prefork:notice] [pid 73200] AH00163: Apache/2.4.41 (Unix) configured -- resuming normal operations
    [Fri Sep 13 21:33:55.011901 2019] [core:notice] [pid 73200] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'
    

    That is, nothing.

So I always end up doing the same thing: trial-and-error.

Is there any way I can instruct Apache to log every single step it tried before concluding it's a 404?

Something like:

  • no match for VirtualHost x
  • no match for VirtualHost y
  • match for VirtualHost z, file not found: /path/to/file

That is, something useful?

BenMorel
  • 4,507
  • 10
  • 57
  • 85

2 Answers2

4

The first thing to check is the output of apachectl -S. It shows which IP is listening on which port and for which virtual host. And it also shows the file and line number which configured it.

Then you can add a GlobalLog directive for all virtual hosts, and increase the LogLevel while debugging, while still keeping your standard CustomLog files.

For example, create the file /etc/apache2/conf-available/temp_debug.conf :

LogLevel trace4
GlobalLog ${APACHE_LOG_DIR}/debug.log "%v:%p %h %l %u %t \"%r\" %>s %O file=%f"

# http://httpd.apache.org/docs/current/mod/mod_log_config.html#formats
# %v    The canonical ServerName of the server serving the request.
# %f    Filename.

Enable it with

sudo a2enconf temp_debug && sudo apachectl graceful

When done, disable the extra logging with

sudo a2disconf temp_debug && sudo apachectl graceful

The trace information will go to your ErrorLog, also indicating which level of trace was needed to make it write to the log.

mivk
  • 4,004
  • 3
  • 37
  • 32
  • If you already have logging turned on all you need to do is add `LogLevel trace4` and you will see the extra tracing in them. – MeSo2 Nov 18 '22 at 14:42
1

Yes. There possible approaches to solve your problem. In my opinion, the best one is to configure different ErrorLog and CustomLog directives per virtualhost, saving into independent files. Another one is to customize your log, inserting the virtualhost using the LogFormat masks (%v, for instance, to log the respective virtualhost). The problem with this method is that if you use some sort of Apache log analyzer, you may stumble into some sort of problem, or will have to configure it to match the new pattern.

Best regards.

Stefano Martins
  • 1,221
  • 8
  • 10