Skip to content

Instantly share code, notes, and snippets.

@amoslanka
Last active July 8, 2021 07:47
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save amoslanka/6720707 to your computer and use it in GitHub Desktop.
Save amoslanka/6720707 to your computer and use it in GitHub Desktop.
Configuration for rsyslog for Nginx and PHP only. Output to /var/log/loggly and send to Loggly as well.
#################
#### MODULES ####
#################
$ModLoad imuxsock # provides support for local system logging
$ModLoad imfile
###########################
#### GLOBAL DIRECTIVES ####
###########################
$SystemLogSocketFlowControl on
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# Filter duplicated messages
# $RepeatedMsgReduction on
#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup adm
###########################
###### INPUT FILES ########
###########################
$InputFileName /var/log/nginx/access.log
$InputFileTag nginx:
$InputFileStateFile stat-nginx-access
$InputFileSeverity info
$InputRunFileMonitor
$InputFileName /var/log/nginx/error.log
$InputFileTag nginx:
$InputFileStateFile stat-nginx-error
$InputFileSeverity info
$InputRunFileMonitor
# (this is a custom php error log location)
$InputFileName /var/log/php/error.log
$InputFileTag php:
$InputFileStateFile stat-php-error
$InputFileSeverity error
$InputRunFileMonitor
#################################
####### OUTPUT TO LOGGLY ########
#################################
# Define the template used for sending logs to Loggly. Do not change this format.
$template LogglyFormat,"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [TOKEN@41058] %msg%\n"
# Send messages to Loggly over TCP using the template.
if $programname == 'nginx' then @@logs-01.loggly.com:514;LogglyFormat
if $programname == 'php' then @@logs-01.loggly.com:514;LogglyFormat
# $DirCreateMode 0700
# $FileCreateMode 0644
if $programname == 'nginx' then /var/log/loggly;LogglyFormat
if $programname == 'php' then /var/log/loggly;LogglyFormat
@amoslanka
Copy link
Author

If you use this, be sure to replace the "TOKEN" in the LogglyFormat with your api token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment