Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like to enable access log in order to see statistics about our service, the problem I'm having is that the $request on the access logs format, saves all the GET parameters (which makes sense because its part of the request)

but I would like to hide this information, so instead of seeing this on the logs:

98.207.174.147 - - [26/Apr/2014:23:59:09 +0000] "GET /v1/api.json?parameter1=value1&paramter2=value2" HTTP/1.1" 200 13449 "-" "httperf/0.9.0"

I would like to see

98.207.174.147 - - [26/Apr/2014:23:59:09 +0000] "GET /v1/api.json" HTTP/1.1" 200 13449 "-" "httperf/0.9.0"
share|improve this question
1  
Use POST requests. –  Michael Hampton Apr 27 at 0:01
    
Its not just for the benchmarking, our service should allow users to run search though GET requests, unfortunately that's not an option for me :( –  rorra Apr 27 at 0:11

1 Answer 1

up vote 3 down vote accepted

You can use log_format directive of ngx_http_log_module .

for example, this format would only show the uri without any query string:

http {
       log_format combined_no_query '$remote_addr - $remote_user [$time_local] '
           '"$uri" $status $body_bytes_sent '
           '"$http_referer" "$http_user_agent"';
       //other configs ...
     }

 server {
       access_log /var/log/nginx/access.log combined_no_query
       //... 
      }

Notice the $uri variable which is used to log only the uri without any query string.

doc for log_format directive : http://nginx.org/en/docs/http/ngx_http_log_module.html

for more variables: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_uri

share|improve this answer
    
Thank you a lot, this was the solution I was looking for :) –  rorra Apr 27 at 3:26
    
Please note you are missing the request method (GET/POST etc.), so be sure to to include $request_method before $uri: '"$request_method $uri" $status $body_bytes_sent ' –  cvaldemar Jun 18 at 4:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.