Can I show the port # in the access/error logs with NGINX ? I can run nginx-debug if that helps.
Debian 11, free NGINX 1.22 downloaded release (not built from source)
Can I show the port # in the access/error logs with NGINX ? I can run nginx-debug if that helps.
Debian 11, free NGINX 1.22 downloaded release (not built from source)
nginx variables documentation on variables shows that $server_port
variable contains the server side port for the request.
nginx log module documentation documents log_format
and access_log
directives.
The default log format is:
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
One can add the port to the end for example for another log format:
log_format combinedwithport '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"' $server_port;
To actually use this format for logs, one needs to define:
access_log /path/to/log/file combinedwithport;
It is recommended to add the port to the end of log line so that possible combined log format parsers can still process the log.