so I’ve modified my nginx.conf file to use custom logging:
##
# Logging Settings
##
# Define a custom log format with request protocol and without the $request part
log_format custom_access 'StatusCode: $status - Remote IP: $remote_addr - User: $remote_user - '
'Time (Local): [$time_local] - Request Method: $request_method - Request URI: $request_uri - '
'Protocol: $server_protocol - Bytes Sent: $body_bytes_sent - '
'Request Time: $request_time - Server Name: $server_name - Upstream Response Time: $upstream_response_time - '
'Referer: "$http_referer" - User Agent: "$http_user_agent" - Forwarded For: "$http_x_forwarded_for"';
# Conditional logging - only log requests that do not have a 200 status code
map $status $loggable {
~^[23] 0;
default 1;
}
access_log /var/log/nginx/access.log custom_access if=$loggable;
After doing a test curl, copying the log in a text editor and adding line breaks to be able to read it better, it resulted in following:
StatusCode: 418
Remote IP: 172.18.0.21
User: -
Time (Local): [08/Aug/2024:09:25:42 +0000]
Request Method: GET
Request URI: /
Protocol: HTTP/1.1
Bytes Sent: 4471
Request Time: 0.004
Server Name: genefit.cc
Upstream Response Time: 0.005
Referer: "-"
User Agent: "curl/7.74.0"
Forwarded For: "VPS_IP, 172.70.175.83"
As you can see, RemoteIP Contains the internal docker network ip of the container, not the IP of whoever made that request.
In Forwarded_For, it shows the real VPS IP and a random IP i’m not aware from what it is.
Questions:
- How can i make remote_addr actually display the IP from which the request came from.
- What is the Purpose of the IP inb the second place of
Forwarded For
? (172.70.175.83)
Thanks in advance,
Toastlover
I inetially made the custom log because the default log wouldn’t show the true remote ip, sadly this did not change with the custom logging in place.