Configuring your Nginx web logs

Nginx offers a variety of webserver functionality, including load balancing, HTTP cache - and of course the HTTP webserver itself.

1) Configure your Syslog

Create a new file in your rsyslog.d directory, we called it 21-Nginx-Logscape.config, inside it place the following

$InputFilePollInterval 10
$PrivDropToGroup adm
$WorkDirectory /var/spool/rsyslog
# Nginx access file:
$InputFileName /var/log/Nginx/access.log
$InputFileTag Nginx-access:
$InputFileStateFile stat-Nginx-access
$InputFileSeverity info
$InputFilePersistStateInterval 20000
#Nginx Error file:
$InputFileName /var/log/Nginx/error.log
$InputFileTag Nginx-error:
$InputFileStateFile stat-Nginx-error
$InputFileSeverity error
$InputFilePersistStateInterval 20000
#Add a tag for Nginx events
template CloudNginx,"LOGSCAPETOKEN:YOUR_SECURITY_TOKEN_HERE LOGSCAPETAG:Nginx <%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% %msg%"
if $programname == 'Nginx-access' then @@;CloudNginx
if $programname == 'Nginx-access' then ~
if $programname == 'Nginx-error' then @@;CloudNginx
if $programname == 'Nginx-error' then ~

You'll also need to check your rsyslog.conf to make sure the following module has been loaded.

$ModLoad imfile
2) Restart the Syslog daemon

Now restart your Syslog daemon.

sudo service rsyslog restart
3) Check Logscape for connectivity

Log into the Logscape Cloud and check the web workspaces to see your data.