【问题标题】:How to Store Server IP in apache log file如何在 apache 日志文件中存储服务器 IP
【发布时间】:2020-08-18 17:24:25
【问题描述】:

我正在使用 AWS AutoScaling 组。我在这里托管了 Apche-Ubuntu 实例。我想通过记录其 ip 来记录哪个服务器提供了内容。

我找到的最接近的是这个 https://ubuntuforums.org/archive/index.php/t-1401710.html(2010 年 2 月 11 日下午 4:07)评论。

【问题讨论】:

    标签: amazon-web-services apache ubuntu autoscaling


    【解决方案1】:

    在 Apache 中,您可以使用指令 LogFormat,它允许您确定每个日志的标题中包含哪些信息。您在 apache2.conf 中创建 LogFormat 字符串,然后在使用 CustomLog 指令时使用这些字符串。

    Apache 帮助中使用的示例:

    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    CustomLog "logs/access_log" common
    

    这意味着 access_log 中的日志将包含以下信息:

    • 远程主机名
    • 远程登录名
    • 远程用户
    • 时间
    • 请求的第一行(加引号)
    • 最终状态
    • 请求的大小(以字节为单位)

    log formats documentation 中有一个%A - Local IP-address

    我从未测试过它,但它可能满足您的需求。

    【讨论】:

    • 请记住,如果这些 AutoScaling 实例位于 Classic 或 Application 负载均衡器之后,您将在日志中看到的作为“客户端”的 IP 将是负载均衡器 IP。您需要 Apache 记录“X-Forwarded-For”标头以查看实际的客户端 IP
    猜你喜欢
    • 2012-09-30
    • 2014-02-23
    • 2011-03-06
    • 2014-02-26
    • 2019-05-02
    • 2015-03-15
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多