matomo-org/docker

Matomo-Docker behind a Nginx Proxy

jbekesi opened this issue · 1 comments

For a configuration of Matomo and docker-compose being served by a Nginx server already in place and dealing with
SSL certificates and such you have to insert some additional config values:

In /var/www/html/config/config.ini.php in the matomo_app_1 container (or whatever name `docker-compose' has
rendered):

[General]
proxy_client_headers[] = HTTP_X_FORWARDED_FOR
proxy_host_headers[] = HTTP_X_FORWARDED_HOST
assume_secure_protocol = 1
force_ssl = 1
trusted_hosts[] = "localhost:<PORT>"
trusted_hosts[] = "<EXTERNAL_HOST>"

In your Nginx config there has to be a section like this:

...

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass <PROXY_CONFIG>;
}
...

...where should be the externally visible port of your docker-compose.yml, <EXTERNAL_HOST> the externally visible hostname your Matomo instance is configured for in Nginx, and <PROXY_CONFIG> your proxy configuration,
e.g. http://localhost:8088.

I'm not sure if every entry is necessary, but this is a working configuration I found after a bit of trying, and perhaps it saves a bit of time for others.

First of all thank you very much for sharing this, can confirm this helped!

Second ... could this be added to the official documentation? I feel like this is such a common use-case that it would deserve having its own documentation page.