<?xml version="1.0" encoding="UTF-8"?>
<snippet>
  <account-id type="integer">3</account-id>
  <body>Nginx does not support syslog by default, so you have to patch it with a third party module. This snippet relies on that you have configured xstow. See &quot;this&quot;:http://snippets.aktagon.com/snippets/188-Installing-git-without-getting-screwed-over-when-it-s-time-to-uninstall-upgrade-or-install-package-maintainer-s-version snippet for instructions on xstow configuration.
&lt;code&gt;
cd /tmp
wget http://sysoev.ru/nginx/nginx-0.6.32.tar.gz
tar zxvf nginx-0.6.32.tar.gz
mv nginx-0.6.32 src-0.6.32-orig
wget &quot;http://wiki.codemongers.com/NginxModules?action=AttachFile&amp;do=get&amp;target=syslog.patch&quot; -O syslog.patch
patch -p0 &lt; syslog.patch
cd src-0.6.32-orig
./configure --prefix=/usr/local/stow/nginx --with-syslog
make
sudo make install
cd /usr/local/stow
sudo xstow nginx
&lt;/code&gt;

I-am-a-noob-at-syslog-disclaimer: This might be a totally wrong way to configure the server and client(s), so it is subject for refinement. In my experience it works though.

Configuring the *client*. Add the following lines to the end of /etc/syslog-ng/syslog-ng.conf and restart syslog-ng with /etc/init.d/syslog-ng restart. Nginx logs in facility local5 and the hostname of the loghost is &quot;loghost&quot;. You could just as well use the IP of the loghost.
&lt;code&gt;
filter f_local5 { facility(local5); };
destination d_loghost {tcp(&quot;loghost&quot; port(514));};
log { source(s_all); filter(f_local5); destination(d_loghost); };
&lt;/code&gt;

Configuring the *server*. Add the following lines to the end of /etc/syslog-ng/syslog-ng.conf and restart syslog-ng with /etc/init.d/syslog-ng restart. Also if you run a cluster of nginx servers it might be wise to put all the output in one file, instead of separate files per host.
&lt;code&gt;
source s_remote { tcp(); };
destination d_clients { file(&quot;/var/log/HOSTS/nginx.$HOST&quot;); };
log { source(s_remote); destination(d_clients); };
&lt;/code&gt;

Test the logging by running this from the client.
&lt;code&gt;
logger -p local5.info Hubbabubba
&lt;/code&gt;</body>
  <comments-count type="integer">0</comments-count>
  <created-at type="datetime">2008-09-17T23:38:12+03:00</created-at>
  <id type="integer">247</id>
  <language-id type="integer">131</language-id>
  <rendered-body>&lt;p&gt;Nginx does not support syslog by default, so you have to patch it with a third party module. This snippet relies on that you have configured xstow. See &lt;a href=&quot;http://snippets.aktagon.com/snippets/188-Installing-git-without-getting-screwed-over-when-it-s-time-to-uninstall-upgrade-or-install-package-maintainer-s-version&quot;&gt;this&lt;/a&gt; snippet for instructions on xstow configuration.
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; cd /tmp
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; wget http://sysoev.ru/nginx/nginx-0.6.32.tar.gz
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; tar zxvf nginx-0.6.32.tar.gz
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt; mv nginx-0.6.32 src-0.6.32-orig
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt; wget &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;http://wiki.codemongers.com/NginxModules?action=AttachFile&amp;amp;do=get&amp;amp;target=syslog.patch&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; -O syslog.patch
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt; patch -p0 &lt;span class=&quot;Operator&quot;&gt;&amp;lt;&lt;/span&gt; syslog.patch
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt; cd src-0.6.32-orig
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt; ./configure --prefix=/usr/local/stow/nginx --with-syslog
&lt;span class=&quot;line-numbers&quot;&gt;   9 &lt;/span&gt; make
&lt;span class=&quot;line-numbers&quot;&gt;  10 &lt;/span&gt; sudo make install
&lt;span class=&quot;line-numbers&quot;&gt;  11 &lt;/span&gt; cd /usr/local/stow
&lt;span class=&quot;line-numbers&quot;&gt;  12 &lt;/span&gt; sudo xstow nginx
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;I-am-a-noob-at-syslog-disclaimer: This might be a totally wrong way to configure the server and client(s), so it is subject for refinement. In my experience it works though.&lt;/p&gt;


	&lt;p&gt;Configuring the &lt;strong&gt;client&lt;/strong&gt;. Add the following lines to the end of /etc/syslog-ng/syslog-ng.conf and restart syslog-ng with /etc/init.d/syslog-ng restart. Nginx logs in facility local5 and the hostname of the loghost is &amp;#8220;loghost&amp;#8221;. You could just as well use the IP of the loghost.
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; filter f_local5 { facility(local5)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; }&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; destination d_loghost {tcp(&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;loghost&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; port(514))&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;}&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; log { source(s_all)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; filter(f_local5)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; destination(d_loghost)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; }&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Configuring the &lt;strong&gt;server&lt;/strong&gt;. Add the following lines to the end of /etc/syslog-ng/syslog-ng.conf and restart syslog-ng with /etc/init.d/syslog-ng restart. Also if you run a cluster of nginx servers it might be wise to put all the output in one file, instead of separate files per host.
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; source s_remote { &lt;span class=&quot;FunctionName&quot;&gt;tcp&lt;/span&gt;()&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; }&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; destination d_clients { file(&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;/var/log/HOSTS/nginx.&lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;$&lt;/span&gt;HOST&lt;/span&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; }&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; log { source(s_remote)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; destination(d_clients)&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt; }&lt;span class=&quot;Operator&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;Test the logging by running this from the client.
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; logger -p local5.info Hubbabubba
&lt;/pre&gt;&lt;/p&gt;</rendered-body>
  <title>Logging nginx to remote loghost with syslog-ng.</title>
  <updated-at type="datetime">2008-09-17T23:47:52+03:00</updated-at>
</snippet>
