Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx: which port received the request?

For testing purposes, I am using nginx to listen on multiple ports when I send distributed http requests. I can see the request be received by nginx - but I need to know which of its ports actually got it. I can't see any options in the logs to flag this.

I guess an ugly alternative is to install multiple instances so their logs are separated, but there must be a better way than this...?

like image 452
annaken Avatar asked May 18 '11 21:05

annaken


1 Answers

Anything you can access as a variable in nginx config, you can log, including non-standard http headers, etc.

The var you want to add is $server_port

log_format  mycustomformat  '$host $remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" $server_port';
access_log /var/log/nginx/access.log mycustomformat;
like image 191
Frank Farmer Avatar answered Sep 17 '22 20:09

Frank Farmer