logging fixes
This commit is contained in:
parent
882a417527
commit
b1a484f4d0
2 changed files with 38 additions and 7 deletions
35
install/nginx-log-format.sh
Normal file
35
install/nginx-log-format.sh
Normal file
|
@ -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
|
|
@ -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";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue