I use Cloudflare for my domains.
I've noticed a situation in my access.log file that when someone attempts to connect directly (via the IP address) the $http_x_forwarded_for value is "-", which is correct and by design as $http_x_forwarded_for isn't being set by Cloudflare.
I want to do the following (see first if block), but nginx won't allow it in the main nginx.conf file. Is there another way to do this?
if ($http_x_forwarded_for = '-') {
$http_x_forwarded_for = $remote_addr;
}
# format: e.g., $http_cf_ipcountry derives from the Cloudflare header HTTP_CF_IPCOUNTRY;
# the others too follow this format
log_format complete '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$host" '
'"$http_x_forwarded_for" "$http_cf_ipcountry" "$http_accept_language"';