Answer the question
In order to leave comments, you need to log in
How to cut nginx logs by $host-access.log files?
There is a proxying nginx in front of the virtual machines, I want to cut the logs by domains into the $host-access.log files of the same name with nginx initially, but something doesn’t work like a stone flower.
http {
upstream first-upstream {
server 12.34.56.1:80;
}
#access_log /var/log/nginx/$host-access.log;
server {
listen 80 default_server;
location / {
proxy_pass http://first-upstream;
#access_log /var/log/nginx/$host-access.log;
}
access_log
. Falls into error.log:...testing "/etc/nginx//html" existence failed (2: No such file or directory) while logging request...
Answer the question
In order to leave comments, you need to log in
So describe root, it is written quite specifically. It is clear that you do not need it, but it is needed for logging to work =)
server {
server_name localhost.com;
# Folder with site content (handy when it matches the domain name)
root /var/www/localhost;
# Setting up logs, each virtual domain has its own log
access_log /var/log/nginx/localhost.com-access.log;
error_log /var/log/nginx/localhost.com-error.log;
I recently wrote a note here, look there it is habrahabr.ru/post/164401/
I'll just quote the documentation that no one reads anyway:
Variables can be used in the file path (0.7.6+), but such logs have some limitations:@ nginx.org/r/access_log/ru
[...]
- at each entry in the log, the existence of the root directory for the request is checked - if this directory does not exist, then the log is not created. Therefore, root and access_log must be described at the same level:
server { root /spool/vhost/data/$host; access_log /spool/vhost/logs/$host; ...
Do not forget that access logs in nginx are not needed because they duplicate Apache, and you don’t need static that worked validly.
But it will add load to the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question