Skip to content

Instantly share code, notes, and snippets.

@jyap808
Created April 13, 2014 05:03
Show Gist options
  • Save jyap808/10570005 to your computer and use it in GitHub Desktop.
Save jyap808/10570005 to your computer and use it in GitHub Desktop.
Nginx Virtual Host Log Format
$ diff -u /etc/nginx/nginx.conf{.ORIG,}
--- /etc/nginx/nginx.conf.ORIG  2014-04-13 04:15:51.907316500 +0000
+++ /etc/nginx/nginx.conf       2014-04-13 05:02:22.807316500 +0000
@@ -30,7 +30,9 @@
        # Logging Settings
        ##
 
-       access_log /var/log/nginx/access.log;
+       log_format vhosts '$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
+
+       access_log /var/log/nginx/access.log vhosts;
        error_log /var/log/nginx/error.log;
 
        ##

Logs can then be parsed with GoAccess

Via: https://github.com/piwik/piwik/tree/master/misc/log-analytics and http://publications.jbfavre.org/web/nginx-vhosts-automatiques-avec-SSL-et-authentification.en

@chk1
Copy link

chk1 commented Apr 10, 2018

To make nginx logging work with the GoAccess VCOMBINED log format you might have to add :$server_port like so:

log_format vcombined '$host:$server_port '
        '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $body_bytes_sent '
        '"$http_referer" "$http_user_agent"';

access_log /var/log/nginx/access.log vcombined;
error_log /var/log/nginx/error.log;

@quocthinh212
Copy link

To make nginx logging work with the GoAccess VCOMBINED log format you might have to add :$server_port like so:

log_format vcombined '$host:$server_port '
        '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $body_bytes_sent '
        '"$http_referer" "$http_user_agent"';

access_log /var/log/nginx/access.log vcombined;
error_log /var/log/nginx/error.log;

Thank you so much !

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