{"id":1473,"date":"2018-10-24T01:17:12","date_gmt":"2018-10-24T01:17:12","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1473"},"modified":"2018-10-24T03:23:03","modified_gmt":"2018-10-24T03:23:03","slug":"piwik-analytics-on-nginx-linuxadmin-io","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/24\/piwik-analytics-on-nginx-linuxadmin-io\/","title":{"rendered":"Piwik Analytics on Nginx &#8211; LinuxAdmin.io"},"content":{"rendered":"<p>Piwik is a open source web site analytics software. It is free and opensource and can be used to track Nginx requests as well as Apache. This guide covers the Nginx configuration and installation of Pikwik. You can read more about Piwik <a href=\"https:\/\/piwik.org\/\">here<\/a>.<\/p>\n<p>If you do not already have Nginx and PHP-PFM installed, please see the following guides<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/nginx-compile-source\/\">How To Install Nginx<\/a><\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/php-fpm-php7-source\/\">How To Install PHP-FPM<\/a><\/p>\n<h2>Install Pikwik<\/h2>\n<p>Create a new directory to contain the piwik analytics data<\/p>\n<p>mkdir \/etc\/nginx\/stats.domain.com<\/p>\n<p>Go to that directory<\/p>\n<p>cd \/etc\/nginx\/stats.domain.com<\/p>\n<p>Download the latest version of Piwik<\/p>\n<p>wget https:\/\/builds.piwik.org\/piwik.zip<\/p>\n<p>Un-compress it<\/p>\n<p>unzip piwik.zip<\/p>\n<p>Create a new database:<\/p>\n<p>mysql -e &#8220;create database pikwik;&#8221;<\/p>\n<p>Create a new database user:<\/p>\n<p>mysql -e &#8220;grant all on pikwik.* to <a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a> idenfied by &#8216;PASSWORD&#8217;;&#8221;<\/p>\n<h2>Configure Nginx<\/h2>\n<p>Create a new server configuration for stats.domain.com<\/p>\n<p>nano \/etc\/nginx\/stats.domain.com.conf<\/p>\n<p>Insert the following, updating references to stats.domain.com with your domain name.<\/p>\n<p>server {<br \/>\nlisten 80;<br \/>\nserver_name stats.domain.com;<\/p>\n<p>access_log \/etc\/nginx\/logs\/stats.domain.com_access.log;<br \/>\nerror_log \/etc\/nginx\/logs\/stats.domain.com_error.log;<\/p>\n<p># Disable all methods besides HEAD, GET and POST.<br \/>\nif ($request_method !~ ^(GET|HEAD|POST)$ ) {<br \/>\nreturn 444;<br \/>\n}<\/p>\n<p>root \/etc\/nginx\/stats.domain.com\/;<br \/>\nindex index.php index.html;<\/p>\n<p># Disallow any usage of piwik assets if referer is non valid.<br \/>\nlocation ~* ^.+.(?:jpg|png|css|gif|jpeg|js|swf)$ {<br \/>\n# Defining the valid referers.<br \/>\nvalid_referers none blocked *.domain.com;<br \/>\nif ($invalid_referer) {<br \/>\nreturn 444;<br \/>\n}<br \/>\nexpires max;<br \/>\nbreak;<br \/>\n}<\/p>\n<p># Support for favicon. Return a 204 (No Content) if the favicon<br \/>\n# doesn&#8217;t exist.<br \/>\nlocation = \/favicon.ico {<br \/>\ntry_files \/favicon.ico =204;<br \/>\n}<\/p>\n<p># Try all locations and relay to index.php as a fallback.<br \/>\nlocation \/ {<br \/>\ntry_files $uri \/index.php;<br \/>\n} #location ~* ^\/(?:index|piwik).php$ {<br \/>\nlocation ~ .php$ {<br \/>\ntry_files $uri =404;<br \/>\nfastcgi_pass 127.0.0.1:9000;<br \/>\nfastcgi_index index.php;<br \/>\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>\ninclude fastcgi_params;<\/p>\n<p>}<\/p>\n<p># Any other attempt to access PHP files returns a 404.<br \/>\n#location ~* ^.+.php$ {<br \/>\n# return 404;<br \/>\n#}<\/p>\n<p># Return a 404 for all text files.<br \/>\nlocation ~* ^\/(?:README|LICENSE[^.]*|LEGALNOTICE)(?:.txt)*$ {<br \/>\nreturn 404;<br \/>\n}<\/p>\n<p>} # server<\/p>\n<p>Edit the main nginx configuration file:<\/p>\n<p>nano \/etc\/nginx\/nginx.conf<\/p>\n<p>Insert the following line at the end:<\/p>\n<p>Include \/etc\/nginx\/stats.domain.com.conf;<\/p>\n<p>Restart nginx<\/p>\n<p>service nginx restart<\/p>\n<p>Once you have done that go ahead and visit stats.domain.com it will ask you to input the MySQL credentials you created earlier. After it has populated the database, it will provide you with code to insert into the site you wish to track. Once that is in place it will start generating the data for you to view inside the pikwik installation.<\/p>\n<p>Jun 5, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/piwik-analytics-nginx\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Piwik is a open source web site analytics software. It is free and opensource and can be used to track Nginx requests as well as Apache. This guide covers the Nginx configuration and installation of Pikwik. You can read more about Piwik here. If you do not already have Nginx and PHP-PFM installed, please see &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/24\/piwik-analytics-on-nginx-linuxadmin-io\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Piwik Analytics on Nginx &#8211; LinuxAdmin.io&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1473","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1473"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1473\/revisions"}],"predecessor-version":[{"id":1538,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1473\/revisions\/1538"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}