I want make dynamic subdomains with logs in separate directories, but have a problem with it:
- If I provide a path to logs like
/var/www/demo/subdomains/$sub/logs/access.log
and same with error, NGINX writes/var/www/demo/subdomains/$sub/logs/error.log" failed (2: No such file or directory)
- If I provide a path like in config now
/var/www/demo/subdomains/logs/$sub-error.log
I have the problem that$sub-access.log
is named correctly likedemo1-access.log
ordemo2-acces.log
, but$sub-error.log
is named just as$sub-error.log
. For 2 domains I have 3 files -demo1-access.log
,demo2-access.log
, and$sub-error.log
.
What do I need to change to make the first method working? The second is fine too, but not so beautiful.
server {
listen 80;
listen [::]:80;
server_name "~^(?<sub>.+)\.deb\.test$";
root /var/www/demo/subdomains/$sub/www;
index index.php index.html;
access_log /var/www/demo/subdomains/logs/$sub-access.log combined;
error_log /var/www/demo/subdomains/logs/$sub-error.log info;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FLIENAME $document_root@fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
location ~ /\.ht {
deny all;
}
}
Adding one more server block with error_log directive works the same:
server {
listen 80;
listen [::]:80;
server_name "~^(?<sub>.+)\.deb\.test$";
error_log /var/www/demo/subdomains/logs/$sub-error.log info;
}