Index: xdebug_stack.c
===================================================================
--- xdebug_stack.c	(revision 3392)
+++ xdebug_stack.c	(working copy)
@@ -447,8 +447,14 @@
 	if (!XG(remote_enabled) && XG(remote_enable) && (XG(remote_mode) == XDEBUG_JIT)) {
 		if (XG(remote_connect_back)) {
 			zval **remote_addr = NULL;
-			zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr);
-			XG(context).socket = xdebug_create_socket(Z_STRVAL_PP(remote_addr), XG(remote_port));
+			if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "X_HTTP_FORWARDED_FOR", 21, (void**)&remote_addr) == FAILURE) {
+				zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr);
+			}
+			if (remote_addr) {
+				XG(context).socket = xdebug_create_socket(Z_STRVAL_PP(remote_addr), XG(remote_port));
+			} else {
+				XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port));
+			}
 		} else {
 			XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port));
 		}
Index: xdebug.c
===================================================================
--- xdebug.c	(revision 3392)
+++ xdebug.c	(working copy)
@@ -1197,7 +1197,9 @@
 			/* Initialize debugging session */
 			if (XG(remote_connect_back)) {
 				zval **remote_addr = NULL;
-				zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr);
+				if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "X_HTTP_FORWARDED_FOR", 21, (void**)&remote_addr) == FAILURE) {
+					zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr);
+				}
 				if (remote_addr) {
 					XG(context).socket = xdebug_create_socket(Z_STRVAL_PP(remote_addr), XG(remote_port));
 				} else {
