Piwik and Reverse Proxy

Piwik generates its URLs used in links and forms based on data in $_SERVER[]. If you are using a reverse proxy in front of your web server, the incoming request URLS are for the internal server. This results in the people from the outside getting 404 errors after the getting the initial landing page.

To work around this, I was able to use Piwik's boostrap.php file. This is loaded first for any Piwik page. I added some code in there to rewrite PHP's $_SERVER[] parameters to match the original request to the proxy. The variables I had to set were


  • $_SERVER['HTTP_HOST']

  • $_SERVER['PHP_SELF']

  • $_SERVER['SCRIPT_NAME']

  • $_SERVER['REQUEST_URI']

Leave a comment

Recent Entries

  • Building a Web Services API with Elgg

    Elgg provides an API for building custom web services. You expose functionality through the web services API by building a plugin and then either publish...

  • Session security and Chrome Frame

    I've run into the nasty problem that Chrome Frame causes to session handling code that uses the user agent in its security. There are applications...

  • Piwik and Elgg

    While Google Analytics may be the most popular analytics service, there are times when you want to use your own hosted solution (intranet, control over...

  • Piwik and Reverse Proxy

    Piwik generates its URLs used in links and forms based on data in $_SERVER[]. If you are using a reverse proxy in front of your...

  • Elgg Unit Tests

    A new component in Elgg 1.7 will be a unit test framework (SimpleTest). I've written a skeleton example of how plugin authors can use the...

Close