From eedb05d656b0bbc2b9eda3e435238a51f31b0065 Mon Sep 17 00:00:00 2001 From: Andy Chambers Date: Sun, 24 May 2015 23:53:24 -0700 Subject: [PATCH] [Fixes #1158] Split nginx logs by $APP * nginx access logs to /var/log/nginx/${APP}-access.log * nginx error logs to /var/log/nginx/${APP}-error.log --- docs/nginx.md | 4 +++- .../nginx-vhosts/templates/nginx.conf.template | 3 +++ tests/unit/nginx-vhosts.bats | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/nginx.md b/docs/nginx.md index d7589ca34..3cfc76311 100644 --- a/docs/nginx.md +++ b/docs/nginx.md @@ -1,6 +1,6 @@ # Nginx -Dokku uses nginx as it's server for routing requests to specific applications. +Dokku uses nginx as it's server for routing requests to specific applications. By default, access and error logs are written for each app to `/var/log/nginx/${APP}-access.log` and `/var/log/nginx/${APP}-error.log` respectively ## TLS/SPDY support @@ -56,6 +56,8 @@ server { listen [::]:80; listen 80; server_name $NOSSL_SERVER_NAME; + access_log /var/log/nginx/${APP}-access.log; + error_log /var/log/nginx/${APP}-error.log; # set a custom header for requests add_header X-Served-By www-ec2-01; diff --git a/plugins/nginx-vhosts/templates/nginx.conf.template b/plugins/nginx-vhosts/templates/nginx.conf.template index 8ed426275..b2cc3df69 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.template +++ b/plugins/nginx-vhosts/templates/nginx.conf.template @@ -2,6 +2,9 @@ server { listen [::]:80; listen 80; server_name $NOSSL_SERVER_NAME; + access_log /var/log/nginx/${APP}-access.log; + error_log /var/log/nginx/${APP}-error.log; + location / { proxy_pass http://$APP; proxy_http_version 1.1; diff --git a/tests/unit/nginx-vhosts.bats b/tests/unit/nginx-vhosts.bats index 5623167ac..d08e7701c 100644 --- a/tests/unit/nginx-vhosts.bats +++ b/tests/unit/nginx-vhosts.bats @@ -53,6 +53,18 @@ assert_http_success() { assert_output "200" } +assert_access_log() { + local prefix=$1 + run [ -a /var/log/nginx/$prefix-access.log ] + assert_success +} + +assert_error_log() { + local prefix=$1 + run [ -a /var/log/nginx/$prefix-error.log ] + assert_success +} + @test "(nginx-vhosts) nginx (no server tokens)" { deploy_app run /bin/bash -c "curl -s -D - $(dokku url $TEST_APP) -o /dev/null | egrep '^Server' | egrep '[0-9]+'" @@ -61,6 +73,12 @@ assert_http_success() { assert_failure } +@test "(nginx-vhosts) logging" { + deploy_app + assert_access_log ${TEST_APP} + assert_error_log ${TEST_APP} +} + @test "(nginx-vhosts) nginx:build-config (wildcard SSL)" { setup_test_tls_wildcard add_domain "wildcard1.dokku.me"