{"id":1695,"date":"2018-10-20T22:21:06","date_gmt":"2018-10-20T19:21:06","guid":{"rendered":"https:\/\/artem.services\/?p=115"},"modified":"2020-03-15T20:47:06","modified_gmt":"2020-03-15T17:47:06","slug":"1695","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1695&lang=en","title":{"rendered":"AWStats &#8212; Nginx"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-203 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/AWStats-Nginx-Logo.png\" alt=\"\" width=\"868\" height=\"177\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/AWStats-Nginx-Logo.png 868w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/AWStats-Nginx-Logo-300x61.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/AWStats-Nginx-Logo-768x157.png 768w\" sizes=\"(max-width: 868px) 100vw, 868px\" \/><\/p>\n<p><strong>AWStats<\/strong> is by default tuned to work with the <strong>Apache<\/strong> log, in this article I will show how to get statistics from <strong>Nginx<\/strong> logs.<\/p>\n<p>Install <strong>Awstats<\/strong> and the <strong>GeoIP<\/strong> module<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nyum install awstats htmldoc GeoIP perl-Geo-IP\r\n<\/pre>\n<p>Install the <strong>Perl<\/strong> handler<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nyum -y install spawn-fcgi fcgi-devel wget\r\nyum -y groupinstall &quot;Development Tools&quot;\r\nmkdir \/tmp\/perl &amp;&amp; cd \/tmp\/perl &amp;&amp; wget http:\/\/github.com\/gnosek\/fcgiwrap\/tarball\/master -O fcgiwrap.tar.gz\r\ntar -xf fcgiwrap.tar.gz &amp;&amp; cd gnosek-fcgiwrap-*\r\n\r\nautoreconf -i\r\n.\/configure\r\nmake\r\nmake install\r\n<\/pre>\n<p><!--more--><\/p>\n<p>Add launch options to the config:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim \/etc\/sysconfig\/spawn-fcgi\r\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nOPTIONS=&quot;-u nginx -g nginx -a 127.0.0.1 -p 9001 -P \/var\/run\/spawn-fcgi.pid -- \/usr\/local\/sbin\/fcgiwrap&quot;\r\n<\/pre>\n<p>\u0421\u0442\u0430\u0432\u0438\u043c \u0432 \u0430\u0432\u0442\u043e\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsystemctl enable spawn-fcgi\r\nsystemctl start spawn-fcgi\r\n<\/pre>\n<p>We bring the <strong>access<\/strong> log of <strong>Nginx<\/strong> to the following form:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim \/etc\/nginx\/nginx.conf\r\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nlog_format stats '$remote_addr - $remote_user [$time_local] &quot;$request&quot; '\r\n'$status $body_bytes_sent &quot;$http_referer&quot; '\r\n'&quot;$http_user_agent&quot;';\r\n<\/pre>\n<p>We re-read the configuration of <strong>Nginx<\/strong>.<\/p>\n<p>Create an <strong>AWStats<\/strong> configuration file for a specific site:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim \/etc\/awstats\/awstats.artem.services.conf\r\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nLogFile=&quot;\/var\/log\/nginx\/access.log&quot;\r\nLogFormat=1\r\nSiteDomain=&quot;artem.services&quot;\r\nHostAliases=&quot;localhost&quot;\r\nDNSLookup=0\r\nDirData=&quot;\/var\/lib\/awstats\/artem.services&quot;\r\nAllowToUpdateStatsFromBrowser=1\r\nLoadPlugin=&quot;geoip GEOIP_STANDARD \/usr\/share\/GeoIP\/GeoIP.dat&quot;\r\nLang=&quot;ru&quot;\r\n<\/pre>\n<p>Copy the <strong>AWStats<\/strong> script to the web directory, where we will go to see the statistics:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncp -a \/usr\/share\/awstats\/wwwroot\/cgi-bin\/* \/home\/artem\/web\/awstats\/\r\n<\/pre>\n<p>Let&#8217;s create <strong>Nginx<\/strong> config for <strong>AWStats<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nserver {\r\n    listen 80;\r\n    server_name artem.services;\r\n    root \/home\/artem\/web\/awstats;\r\n\r\n    location \/ {\r\n        rewrite ^ http:\/\/artem.services\/awstats.pl?config=artem.services;\r\n    }\r\n\r\n    location \/icon\/ {\r\n        alias \/usr\/share\/awstats\/wwwroot\/icon\/;\r\n    }\r\n\r\n    location \/css\/ {\r\n        alias \/usr\/share\/awstats\/wwwroot\/css\/;\r\n    }\r\n\r\n    location \/js\/ {\r\n        alias \/usr\/share\/awstats\/wwwroot\/js\/;\r\n    }\r\n\r\n    location ~ \\.pl$ {\r\n        access_log off;\r\n        fastcgi_pass   127.0.0.1:9001;\r\n        fastcgi_index  awstats.pl;\r\n        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n        include        \/etc\/nginx\/fastcgi_params;\r\n    }\r\n}\r\n<\/pre>\n<p>My statistics were filled in through the script and the instructions of the config, but without specifying the domain name in the file name, and through the browser everything is ok and the statistics are updated, so the following went into my crown:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwget -O \/dev\/null http:\/\/artem.services\/awstats\/awstats.pl?framename=mainright\\&amp;update=1\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; AWStats is by default tuned to work with the Apache log, in this article I will show how to get statistics from Nginx logs. Install Awstats and the GeoIP module Install the Perl handler<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[405],"tags":[1347,345],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1695"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1695"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1695\/revisions"}],"predecessor-version":[{"id":1697,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1695\/revisions\/1697"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}