Lost tracking traffic from the website (reverse proxy conf)

  • My Mautic version is: 4.0.2
  • My PHP version is: 7.4.24
  • My Database type and version is: Mysql 5.7.34-37
  • These errors are showing in the log: Unfortunately there are no errors in the Mautic’s log as well in the DevTools console on the website.
  • This Mautic instance is set behind the reverse proxy.

Main problem is that Mautic is not tracking all the visitors. Google Analytics shows that there are around 7k unique visits on the page per day, but Mautic tracks only around 20-30 of them(as anonymous contacts ofc). These tracked users use different devices, operation systems and are from different locations so there is no common thing for them that will be helpful with diagnosis.

I’ve tried to debug this issue and looks like Mautic don’t create cookies in the browser(checked on smartphone, different computer with several browsers as well as on different ISP). When I embed Mautic’s form on the page and submit my email to create new contact then cookies are created but Mautic don’t track any further moves on the site. No things change in the newly created contact’s log.

I’ve got also a 2nd Mautic instance that is hosted on external VPS server(without proxy) so I made a test. I implemented the tracking code on the website to point to this 2nd instance and this Mautic tracked ca. 40 new contacts in around 5 minutes. So it looks like on this 1st Mautic traffic is lost on server level.

Unfortunately I don’t have access to the server but I am looking for any clues for SysAdmin.

I am wonder if anyone maybe have an example configuration of Apache server and reverse proxy that can resolve that kind of Mautic’s issue?

Steps I have tried to fix the problem:
I’ve tried to add our proxy ip addresses to the “Trusted proxies” field in configuration.

Thank you in advance for any piece of information about possible solutions.

P.S We’ve already faced the problem with redirection loop between https and http that we solved bu adding $_SERVER[‘HTTPS’] = ‘on’ to the configuration.

Hi @ mtch9, Did you find a solution for this? Thanks.

Yes, we managed to solve this. First I found a solution on the internet(sorry but I don’t remember now who is the author of this). It is based on the CloudFlare setup and looks like this:

if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false )
{
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '443';
define('FORCE_SSL_ADMIN', true);
}

// keep in mind that, you should use the X-REAL-IP or other header set from your proxy, not this one if you are not using cloudflare
if (array_key_exists( 'HTTP_CF_CONNECTING_IP', $_SERVER)) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

if ( isset($_SERVER['HTTP_X_FORWARDED_HOST']))
{
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

Based on this we’ve looked into our HAProxy configuration and added headers to pass the IP:

http-request add-header X-Forwarded-For %[src]
http-request set-header X-Forwarded-Port %[dst_port]

and to index.php

$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '443';
define('FORCE_SSL_ADMIN', true);

$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];

Hope this solution will be useful for anyone with that kind of issue.

M.

1 Like