The $proxy_add_x_forwarded_for is equal to $http_x_forwarded_for,$remote_addr, and the $remote_addr variable will be changed when http_realip_module is used. So you will not get the last proxy addr in that header. Changing the order of directives won’t have an effect because nginx configuration is declarative.
When http_realip_module is used, the $realip_remote_addr variable (nginx >= 1.9.7) can be used as the original $remote_addr. So you can set your X-Forwarded-For header like this:
proxy_set_header X-Forwarded-For "$http_x_forwarded_for, $realip_remote_addr";