Question: I have the following setup

* <https://example.net> (my website running on Nginx)
* nn.nn.nn.nn (my Piwik server which is only accessible via its IP address)

On my web pages I have the usual Piwik snippet

```
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
 var u="https://example.net/piwik/";
 ...

```

with Nginx configured as 

```
    location ^~ /piwik/ {
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_pass https://nn.nn.nn.nn/piwik/;
    }

```

From the Piwik documentation I figured that I also needed a few changes to my `config.ini.php` file

```
[General]
proxy_client_headers[] = HTTP_X_FORWARDED_FOR
proxy_host_headers[] = HTTP_X_FORWARDED_HOST
trusted_hosts[] = nn.nn.nn.nn
trusted_hosts[] = example.net

```

With this setup I can login to Piwik and administer it via the url `https://example.net/piwik`. When I browse to pages on my site I see the activity turn up in Piwik as expected. However, the IP address that is recorded is stubbornly stuck at `nn.nn.nn.nn` rather than the real IP address of the visitor in question.

Clearly, I am doing something wrong here but I am not sure what it might be. I hope that someone here will be able to provide the right answer.

Answer: 
For the benefit of others running into this thread I am reproducing the configuration that eventually worked for me

```
    location ^~ /piwik/ {
    proxy_pass https://nn.nn.nn.nn/piwik/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
  }

```

with the *Piwik side* `config.ini.php` containing

```
[General]
proxy_client_headers[] = "HTTP_X_FORWARDED_FOR"
proxy_client_headers[] = "X-Real-IP"
proxy_host_headers[] = "HTTP_X_FORWARDED_HOST"
proxy_ips[] = "nn.nn.nn.nn"

```

Note that the assignments need to be quoted strings.
You have configured Piwik to expect an `X_FORWARDED_FOR` and `X_FORWARDED_HOST` header, then fail to set them in the reverse proxy. Try:

```
location ^~ /piwik/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass https://nn.nn.nn.nn/piwik/;
}

```