title: Configuration for Piwik behind nginx reverse proxy with rewrite
body: <p>I'm using Piwik behind an Nginx reverse proxy and Piwik is running on an Apache Server. I also use a rewrite rule ( /piwik/ to / ).</p>
  
  <p>For Chrome and Safari on Mac the login process for Piwik isn't working (I only got the general error message to configure browser cookies and proxy server).</p>
  
  <p>But my current configuration is working in FirefoxDeveloperEdition for Mac:</p>
  
  <p>nginx.conf:</p>
  
  <pre><code>location /piwik {
       rewrite             ^/piwik/(.*)$ /$1  break;
       proxy_pass          http://piwik;
       proxy_set_header    Host $host;
       proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header    X-Forwarded-Host $http_host/piwik;
  }
  </code></pre>
  
  <p>config.ini.php</p>
  
  <pre><code>[General]
  proxy_client_headers[] = HTTP_X_FORWARDED_FOR
  proxy_host_headers[] = HTTP_X_FORWARDED_HOST
  </code></pre>
  
  <p>When I remove the <code>/piwik</code> in nginx.conf to:</p>
  
  <pre><code>    proxy_set_header    X-Forwarded-Host $http_host;
  </code></pre>
  
  <p>The login is working but I got 2 other problems:</p>
  
  <ul>
  <li>after login I got a wrong redirect to the root <code>/</code> (not Piwik anymore), but after reopening Piwik, I'm logged in</li>
  <li>the logo is missing because of the wrong url <code>http://localhost:2020/plugins/Morpheus/images/logo.svg</code> instead of <code>http://localhost:2020/piwik/plugins/Morpheus/images/logo.svg</code></li>
  </ul>
  
  <p>I also would keep the rewrite rule, because the Apache Server is a universal docker container.</p>
  
  <p>Probably I have to analyse the failing authentification condition, but I didn't find the correct line yet.</p>