title: How to access matomo via a subpage on nginx Ubuntu
body: <p>I am using an Ubuntu 18.04.5 LTS webserver that is configured with nginx. The server is running and I can access any file on my mainpage example.com. Now I want to install matomo on the server. However, I can only manage to access the installation via my root url <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a>. Whenever I try to move the Matomo-access to a subpage e.g. example.com/matomo/ my sever sends a 404 instead. I think I have made a mistake in creating a configuration setup for calling subpages, but I cannot figure out what went wrong. I am new to nginx and have spent the last 2 days testing for a solution. Any help would be highly appreciated. Please find my server.conf, as well as the matomo.conf below.</p>
  <p>My server config-file is as follows:</p>
  <pre><code>server {
      listen                  443 ssl http2;
      listen                  [::]:443 ssl http2;
      server_name             www.example.com;
      set                     $base /var/www/example.com;
      root                    $base/public;
  
      # SSL
      ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
      ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
      ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
  
      # security
      include                 nginxconfig.io/security.conf;
  
      # logging
      access_log              /var/log/nginx/example.com.access.log;
      error_log               /var/log/nginx/example.com.error.log warn;
  
      # index.php
      index                   index.php;
  
      # index.php fallback
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      # handle .php
      location ~ \.php$ {
          fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
          include      nginxconfig.io/php_fastcgi.conf;
      }
  } 
  </code></pre>
  <p>My matomo.conf:</p>
  <pre><code>server {
      listen 443 ssl http2;
      server_name www.example.com/subpage example.com/subpage; 
      access_log /var/log/nginx/matomo.access.log;
      error_log /var/log/nginx/matomo.error.log;
  
  
      ## SSL
      ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; 
      ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
  
      add_header Referrer-Policy origin always; 
      add_header X-Content-Type-Options &quot;nosniff&quot; always;
      add_header X-XSS-Protection &quot;1; mode=block&quot; always;
  
      root /var/www/example.com/subpage/matomo/; # path to matomo instance
  
      index index.php;
  
      ## only allow accessing the following php files
      location ~ ^/(index|matomo|piwik|js/index|plugins/HeatmapSessionRecording/configs)\.php {
          include snippets/fastcgi-php.conf;
          fastcgi_param HTTP_PROXY &quot;&quot;; 
          fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 
      }
  
      ## deny access to all other .php files
      location ~* ^.+\.php$ {
          deny all;
          return 403;
      }
  
      ## serve all other files normally
      location / {
          #try_files $uri $uri/ =404;
      }
  
      ## disable all access to the following directories
      location ~ ^/(config|tmp|core|lang) {
          deny all;
          return 403; # replace with 404 to not show these directories exist
      }
  
      location ~ /\.ht {
          deny  all;
          return 403;
      }
  
      location ~ js/container_.*_preview\.js$ {
          expires off;
          add_header Cache-Control 'private, no-cache, no-store';
      }
  
      location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2|json)$ {
          allow all;
          ## Cache images,CSS,JS and webfonts for an hour
          ## Increasing the duration may improve the load-time, but may cause old files to show after an Matomo upgrade
          expires 1h;
          add_header Pragma public;
          add_header Cache-Control &quot;public&quot;;
      }
  
      location ~ ^/(libs|vendor|plugins|misc/user|node_modules) {
          deny all;
          return 403;
      }
  
      ## properly display textfiles in root directory
      location ~/(.*\.md|LEGALNOTICE|LICENSE) {
          default_type text/plain;
      }
  }
  # vim: filetype=nginx
  </code></pre>