如何为我的 Apache 2.4 VirtualHost 编写条件 CustomLog 语句?
How do I write a conditional CustomLog statement for my Apache 2.4 VirtualHost?
我正在使用以下版本的 Apache (2.4) ...
$ sudo apachectl -v
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 24 2019 13:45:48
我想在我的虚拟主机块中编写自定义日志指令,以便主机 headers 匹配我的域转到一个日志,所有其他的转到另一个日志...
<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>
但是,上面的代码产生了这个错误
$ 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)
如何正确设置自定义日志语句?
我认为应该引用整个表达式,连同 "expr=",即:
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'"
见https://httpd.apache.org/docs/2.4/expr.html#examples,最后一个例子
我正在使用以下版本的 Apache (2.4) ...
$ sudo apachectl -v
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 24 2019 13:45:48
我想在我的虚拟主机块中编写自定义日志指令,以便主机 headers 匹配我的域转到一个日志,所有其他的转到另一个日志...
<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>
但是,上面的代码产生了这个错误
$ 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)
如何正确设置自定义日志语句?
我认为应该引用整个表达式,连同 "expr=",即:
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'"
见https://httpd.apache.org/docs/2.4/expr.html#examples,最后一个例子