Apache server - multiple directories, different error logs

I have two directories in / var / www (say / var / www / app1 and / var / www / app 2) whose error logs I want to send to different files. Both are in the same domain, so I think I can’t host them under different virtual hosts. So, for example, I would refer to them as follows:

http: // localhost / app1

http: // localhost / app2

I came across this page:

Create access logs for different subdirectories in Apache

whose solution works great for access logs. However, the "env" argument does not seem to work with the ErrorLog directive.

Prior to this “discovery”, I worked on this, which seems to be 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>

, . , - ErrorLog , . ! !

+6
3

Directory / VirtualHost? <Directory /var/www/app1> <Directory />

Apache ErrorLog docs server config, virtual host - , ErrorLog a VirtalHost, a Directory. , , SetEnvIf Env. , , - SetEnvIf Request_URI ^\/a1\/ a1 SetEnvIf Request_URI ^\/a2\/ !a1. a1.

+8

: proxypass .

Apache:

a2enmod authz_core dir proxy proxy_http

/ ../

127.0.0.1       localhost
127.0.0.1       a.localhost
127.0.0.1       b.localhost

/etc/apache2/sites-available/default.conf

<VirtualHost *:80>
        ServerName localhost
        ServerAdmin fake@mail.com
        DocumentRoot "/dev/null"

        ProxyPass /a http://a.localhost/
        ProxyPassReverse /a http://a.localhost/
        ProxyPass /b http://b.localhost/
        ProxyPassReverse /b http://b.localhost/

        LogLevel debug

        ErrorLog ${APACHE_LOG_DIR}/default-error.log
        CustomLog ${APACHE_LOG_DIR}/default-access.log combined

</VirtualHost>

/etc/apache2/sites-available/a.conf

<VirtualHost *:80>
        ServerName a.localhost
        ServerAdmin fake@mail.com
        DocumentRoot "/Publikoa/a"

        <Directory "/Publikoa/a">
                DirectoryIndex index.html
                Require all granted
        </Directory>

        LogLevel debug

        ErrorLog ${APACHE_LOG_DIR}/a-error.log
        CustomLog ${APACHE_LOG_DIR}/a-access.log combined

</VirtualHost>

/etc/apache2/sites-available/b.conf

<VirtualHost *:80>
        ServerName b.localhost
        ServerAdmin fake@mail.com
        DocumentRoot "/Publikoa/b"

        <Directory "Publikoa/b">
                DirectoryIndex index.html
                Require all granted
        </Directory>

        LogLevel debug

        ErrorLog ${APACHE_LOG_DIR}/b-error.log
        CustomLog ${APACHE_LOG_DIR}/b-access.log combined

</VirtualHost>

:

a2ensite default a b

apache:

/etc/init.d/apache2 restart
+1

Set an individual identifier for each directory, and you can separate the logs into directories, for example like this:

<Directory app1>
    SetEnv app1
</Directory>
<Directory app2>
    SetEnv app2
</Directory>
CustomLog ${APACHE_LOG_DIR}/site1.log combined env=subwebsite1
CustomLog ${APACHE_LOG_DIR}/site2.log combined env=subwebsite2
0
source

All Articles