If your service (url) is accessible and all need headers set but nginx returned 502 error – try to enable SNI. It can be very actual for reverse proxy AWS services (API Gateway, CloudFront and etc)
For the fix, try to enable proxy_ssl_server_name in the location section
:
proxy_ssl_server_name on;
Sample of configuration (for reverse proxy for AWS CloudFront):
location / {
proxy_pass https://random_value.execute-api.us-east-1.amazonaws.com;
proxy_ssl_protocols TLSv1.2;
proxy_ssl_server_name on;
}