Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

apache2 - Apache server -- multiple directories, different error logs

I have two directories in /var/www (say, /var/www/app1 and /var/www/app2) whose error logs I want sent to different files. Both are under the same domain, so I think that I can't put them under different virtual hosts. So, for example, I would access them as:

http://localhost/app1

http://localhost/app2

I came across this page:

Generate access logs for different subdirectories in Apache

whose solution works perfectly for the access logs. However, the "env" argument doesn't seem to work with the ErrorLog directive.

Before this "discovery", I was working on this, which seems wrong:

<VirtualHost *:80>
  ServerAdmin ray@localhost

  DocumentRoot /var/www/app1

  <Directory />
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order deny,allow
    allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/app1/error.log

  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/app1/access.log combined
</VirtualHost>

I'm somewhat lost about what I should be doing. That is, if there is some way to get ErrorLog to work or if I should keep trying with configuring a virtual host for each directory. Any help would be appreciated! Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why do you set Directory options for / in the VirtualHost context? Use <Directory /var/www/app1> instead of <Directory />

Due to the Apache ErrorLog directive docs its context is server config, virtual host - which means that it's only possible to define ErrorLog for the whole server or for a VirtalHost, not for a Directory. So if you want to send different logs to different files, try to use SetEnvIf to set an Env variable. Depeding on the directory where you are, it should be something like SetEnvIf Request_URI ^/a1/ a1 and SetEnvIf Request_URI ^/a2/ !a1. Then write logs depending on the a1 environment variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...