One correction - /tf/test.php - This file sets the header - header('X-ErrorPage: /tf2/test.php'); and then sends header("HTTP/1.1 401 Unauthorized"); Posted at Nginx Forum: http://forum.nginx.org/read.php?2,222520,222553#msg-222553