nginx - How to configure access_log file in if condition
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 17:29:38
0
1
703

I hope to locate the access logs of different UAs into different access_logs, but it seems that the access_log parameter is not allowed to be placed in the if.
I don't want to locate different requests to different locations through methods such as rewrite. How can I specify accesss_log based on UA ​​in the same location?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
淡淡烟草味

It can be configured like this, there should be a better way to write it.

        location /log {
            if ($http_user_agent ~ MSIE ) {
                  access_log /var/log/msie.log;
            }
            if ($http_user_agent ~ Opera ) {
                  access_log /var/log/opera.log;
            }
            if ($http_user_agent ~ Webkit ) {
                  access_log /var/log/webkit.log;
            }
            if ($http_user_agent ~ Mozilla ) {
                  access_log /var/log/mozilla.log;
            }
            add_header "Content-Type" "text/plain;charset=UTF-8";
            return 200  "$http_user_agent";
        }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!