I am using Haproxy to enable running a websocket server and Lighttpd web server on the same machine. I want to retrieve the machines external IP address from the web application running on the Lighttpd server.
Without haproxy this works:
PHP
<?php
$myip = $_SERVER['SERVER_ADDR'];
$myurl = 'http://'.$myip.'/pathToProject/';
define('URL', $myurl);
?>
But behind the proxy $_SERVER['SERVER_ADDR']; returns 127.0.0.1 which does not work with the PHP framework I am using.
haproxy.conf
global
maxconn 4096
nbproc 1
defaults
mode http
frontend all 0.0.0.0:80
timeout client 86400000
default_backend www_backend
acl is_websocket hdr(Upgrade) -i WebSocket
acl is_websocket hdr_beg(Host) -i ws
use_backend socket_backend if is_websocket
backend www_backend
balance roundrobin
option forwardfor
timeout server 30000
timeout connect 4000
server apiserver 127.0.0.1:8080 weight 1 maxconn 1024 check
backend socket_backend
balance roundrobin
option forwardfor
timeout queue 5000
timeout server 86400000
timeout connect 86400000
server apiserver 127.0.0.1:8082 weight 1 maxconn 1024 check