Nginx add_header for a 50* page
Solution 1:
The documentation states that add_header "Adds the specified field to a response header provided that the response code equals 200, 204, 206, 301, 302, 303, 304, or 307. A value can contain variables." So it doesn't work with a 502.
I forgot to add that you can use the third party headers more module to add headers to other codes. You'll probably have to recompile to add it, though.
Solution 2:
Since Nginx 1.7.5 you can use always
to add a header irrespective of the response code:
add_header X-Test "blahblahblah" always;