Best way to log POST data in Apache?

前端 未结 8 1235
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 04:40

Imagine you have a site API that accepts data in the form of GET requests with parameters, or as POST requests (say, with standard url-encoded, &-separated POST data).

相关标签:
8条回答
  • 2020-11-27 04:52

    Though It's late to answer. This module can do: https://github.com/danghvu/mod_dumpost

    0 讨论(0)
  • 2020-11-27 04:56

    Not exactly an answer, but I have never heard of a way to do this in Apache itself. I guess it might be possible with an extension module, but I don't know whether one has been written.

    One concern is that POST data can be pretty large, and if you don't put some kind of limit on how much is being logged, you might run out of disk space after a while. It's a possible route for hackers to mess with your server.

    0 讨论(0)
  • 2020-11-27 04:57

    I would do it in the application, actually. It's still configurable at runtime, depending on your logger system, of course. For example, if you use Apache Log (log4j/cxx) you could configure a dedicated logger for such URLs and then configure it at runtime from an XML file.

    0 讨论(0)
  • 2020-11-27 04:58

    You can also use the built-in forensic log feature.

    0 讨论(0)
  • 2020-11-27 05:00

    You can use [ModSecurity][1] to view POST data.

    Install on Debian/Ubuntu:

    $ sudo apt install libapache2-mod-security2
    

    Use the recommended configuration file:

    $ sudo mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
    

    Reload Apache:

    $ sudo service apache2 reload
    

    You will now find your data logged under /var/log/apache2/modsec_audit.log

    $ tail -f /var/log/apache2/modsec_audit.log
    --2222229-A--
    [23/Nov/2017:11:36:35 +0000] 
    --2222229-B--
    POST / HTTP/1.1
    Content-Type: application/json
    User-Agent: curl
    Host: example.com
    
    --2222229-C--
    {"test":"modsecurity"}
    
    0 讨论(0)
  • 2020-11-27 05:02

    You can install mod_security and put in /etc/modsecurity/modsecurity.conf:

    SecRuleEngine On
    SecAuditEngine On
    SecAuditLog /var/log/apache2/modsec_audit.log
    SecRequestBodyAccess on
    SecAuditLogParts ABIJDFHZ
    
    0 讨论(0)
提交回复
热议问题