Issue
I'm using the following version of Apache (2.4) ...
$ sudo apachectl -v
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 24 2019 13:45:48
I want to write custom log directives in my virtual host block such that host headers taht match my domain go to one log and all others go to a different log ...
<VirtualHost *:80>
ServerName mydomain.com
# Use the Host header to determine where to log
# Use the Host header to determine how to respond.
CustomLog /var/log/httpd/access_log "%h %l %u %t \"%r\" %>s %b" expr="%{HTTP_HOST} == 'mydomain.com'"
CustomLog /var/log/httpd/garbage_access_log "%h %l %u %t \"%r\" %>s %b" expr="%{HTTP_HOST} != 'mydomain.com'"
Alias /static /var/www/html/frontpage/static
<Directory /var/www/html/frontpage/static>
Require all granted
</Directory>
# Next, add the following directory block
<Directory /var/www/html/frontpage>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess frontpage python-home=/var/www/html/venv python-path=/var/www/html
WSGIProcessGroup frontpage
WSGIScriptAlias / /var/www/html/frontpage_project/wsgi.py
</VirtualHost>
However, the above is producing this error
$ sudo apachectl configtest
AH00526: Syntax error on line 6 of /etc/httpd/conf.d/mydomain.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" or "expr=" clause (see docs)
How do I set up the custom log statements properly?
Solution
I think that the whole expression should be quoted, together with the "expr=", i.e:
CustomLog /var/log/httpd/access_log "%h %l %u %t \"%r\" %>s %b" "expr=%{HTTP_HOST} == 'mydomain.com'"
CustomLog /var/log/httpd/garbage_access_log "%h %l %u %t \"%r\" %>s %b" "expr=%{HTTP_HOST} != 'mydomain.com'"
See https://httpd.apache.org/docs/2.4/expr.html#examples, the last example
Answered By - Mafor Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.