NGINX: display reverse proxy headers

If you are having trouble with a web application sitting behind a reverse proxy, debugging can be facilitated by having your (backend) web-server displaying the headers that it receives.

<?php
echo “<h1>Headers received from the reverse proxy</h1>";
$headers =  getallheaders();
foreach($headers as $key=>$val){
  echo $key . ': ' . $val . '<br>';
}
?>
Commandparameter 1parameter 2output
proxy_set_headerX-Real-IP$remote_addr;IP Address of client
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;IP Address of client
proxy_set_headerX-Forwarded-Host$server_name;called vhost
proxy_set_headerX-Forwarded-Proto$scheme;https or http
proxy_set_header
Header commands and outputs

If you want to test how your page and headers look like from outside, call it from a site like https://testlocal.ly .

Leave a Reply