Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Im trying to setup a server with apache where each user has a logs folder in his home folder and all error/access logs are store in that folder.

My current setup:

<VirtualHost *:80>
  DocumentRoot /home/user/public_html

  ErrorLog /home/user/logs/error.log
  CustomLog /home/user/logs/access.log combined
  LogLevel info

</VirtualHost> 


<VirtualHost *:80>
 DocumentRoot /home/user1/public_html

 ErrorLog /home/user1/logs/error.log
 CustomLog /home/user1/logs/access.log combined
 LogLevel info

</VirtualHost> 

The problem with this setup is that if i access the site of user1

  http://localhost/~user1/

all logs are stored into /home/user/logs/ instead of /home/user1/logs/. How can i fix this so that the logs will be stored in the right place?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

CustomLog for apache 2.2 is a per server or per virtual-host setting and the http://localhost/~user1/ and http://localhost/~user2/ type URI scheme are all aliases within the same default virtual-host.

Something like the following works for the CustomLog (ErrorLog doesn't seem to support the env modifier)

<VirtualHost *:80>
  DocumentRoot /var/www/html
  ErrorLog logs/error_log

  SetEnvIf Request_URI ^~user1 user1
  SetEnvIf Request_URI ^~user2 user2

  CustomLog /home/user1/logs/access.log combined env=user1
  CustomLog /home/user2/logs/access.log combined env=user2

 ...
</VirtualHost>
share|improve this answer
    
i didnt set ServerName because i dont have a domain only ip –  blejzz May 19 '12 at 12:00
    
ok, I see a possibility. let me make a test –  Tom H May 19 '12 at 12:08
add comment

You need to consider that, with a non-trivial amount of users, giving each his own logs will place extra resource requirements on apache.

There is a simple limit on the number of log files it can handle - the system's file descriptor limit.

Additionally, you cannot split the error log within a single vhost.

share|improve this answer
    
this is just for testing and research purposes –  blejzz May 19 '12 at 12:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.