kaltura / nginx-kafka-log-module

Send Kafka messages from Nginx
BSD 2-Clause "Simplified" License
65 stars 22 forks source link

location -> if(...) {kafka_log} - kafka_log directive is not allowed here #13

Open marinaaaniram opened 1 year ago

marinaaaniram commented 1 year ago

I'm trying to do:

location / {
         if ($download_url) {
            kafka_log kafka:topic $download_log;
         }
}

but got error: "kafka_log" directive is not allowed here

So, what should I do if I need to log only certain URLs? And in the location I have a lot of other settings, so I don’t want to take these urls to another location and duplicate half of the config...

erankor commented 1 year ago

Right, kafka_log is not allowed in an if block.

What you can do is use variables in the expression for topic - if the expression evaluates to an empty string, the module does not send any message. For example, the sample conf you pasted could be rewritten to something like this -

http {
    map $download_url $topic {
        "" "";
        default my_topic_name;
    }

    server {
        location / {
            kafka_log kafka:$topic $download_log;
        }
    }
}