Apache2中的ServerName日志

时间:2018-03-25 09:55:57

标签: apache ubuntu-16.04 apache2.4

我在我的Ubuntu 16.04机器上运行apache2.4。 我在/ etc / apache2 / sites-available中设置了两个Document root,每个都有不同的ServerName。无论如何都要配置日志以捕获ServerName,因为我想知道站点发出请求或记录DocumentRoot。

<VirtualHost *:80>
        ServerName www.first.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/first
        LogFormat "%{Host}i%U%q" combined
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我已在同一个Ubunutu框中将www.first.com设置为127.0.0.1,我试图从同一个框中访问www.first.com。 access.log仍然没有显示www.first.com。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我对Custom Log Formats章节的掌握是你需要%v格式字符串:

%v  The canonical ServerName of the server serving the request.

这意味着虚拟主机如:

ServerName example.com
ServerAlias example.net
ServerAlias example.org

...无论入口点是什么,始终记录为example.com

此外,标准combined昵称是:

"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""

你当然可以编辑它,但这有点令人困惑。您可能需要指定其他名称,如LogFormat示例中所示:

LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common