diff --git a/install/nginx-log-format.sh b/install/nginx-log-format.sh new file mode 100644 index 0000000..90a2936 --- /dev/null +++ b/install/nginx-log-format.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Define the log format +LOG_FORMAT='log_format domain_combined '\''$host $remote_addr - $remote_user [$time_local] '\ +''\"$request\" $status $body_bytes_sent '\ +''\"$http_referer\" \"$http_user_agent\"'\'';' + +# Check if we're root +if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit 1 +fi + +# Backup the original config +cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak + +# Check if format already exists +if grep -q "log_format domain_combined" /etc/nginx/nginx.conf; then + echo "domain_combined format already exists" + exit 0 +fi + +# Add the format after the first 'http {' line +sed -i "/^http {/a \ ${LOG_FORMAT}" /etc/nginx/nginx.conf + +# Test the nginx config +nginx -t + +if [ $? -eq 0 ]; then + echo "Successfully added domain_combined log format" +else + echo "Error in nginx config, reverting..." + mv /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf + exit 1 +fi diff --git a/site-config.conf b/site-config.conf index f324d51..dbe9ce2 100644 --- a/site-config.conf +++ b/site-config.conf @@ -27,13 +27,9 @@ server { # Subdomain handling set $subdomain ''; set $full_root "/var/www/$DOMAIN/_main/www"; - set $access_log_path "/var/www/$DOMAIN/logs/main.access.log"; - set $error_log_path "/var/www/$DOMAIN/logs/main.error.log"; if ($host ~* ^([^.]+)\.$DOMAIN$) { set $subdomain $1; set $full_root "/var/www/$DOMAIN/subdomains/$subdomain/www"; - set $access_log_path "/var/www/$DOMAIN/logs/$subdomain.access.log"; - set $error_log_path "/var/www/$DOMAIN/logs/$subdomain.error.log"; } root $full_root; @@ -81,8 +77,8 @@ server { } # Logging - access_log /var/log/nginx/access.log; + access_log /var/log/nginx/access.log domain_combined; error_log /var/log/nginx/error.log; - access_log $access_log_path; - error_log $error_log_path; + access_log "/var/www/$DOMAIN/logs/access.log" domain_combined; + error_log "/var/www/$DOMAIN/logs/error.log"; }