I'm setting up multiple apps on a server using Apache2 for "administrative" bits (like providing https, routing etc) and currently hosting them on different routes on the same domain, like
example.com/app1
example.com/app2
For one app, I've used
<VirtualHost *:443>
ServerName example.com # my domain here
ProxyPass /app1/ http://127.0.0.1:1234/ # app's custom port here
ProxyPassReverse /app1/ http://127.0.0.1:1234/ # and here
ErrorLog ${APACHE_LOG_DIR}/app1_error.log
CustomLog ${APACHE_LOG_DIR}/app1_access.log combined
# ssh/https settings here
</VirtualHost>
Then, I've learned that there can be only one virtual host per domain, so I've added another proxy to set the correct routing:
<VirtualHost *:443>
ServerName example.com
ProxyPass /app1/ http://127.0.0.1:1234/
ProxyPassReverse /app1/ http://127.0.0.1:1234/
ProxyPass /app2/ http://127.0.0.1:2234/
ProxyPassReverse /app2/ http://127.0.0.1:2234/
ErrorLog ${APACHE_LOG_DIR}/app1_error.log
CustomLog ${APACHE_LOG_DIR}/app1_access.log combined
# ssh/https settings here
</VirtualHost>
Now I wonder how do I set different logs for different apps. Can I use Directory
for proxies and do something like this? I've tried
<VirtualHost *:443>
ServerName example.com
<Directory /app1/>
SetEnv app1
ProxyPass /app1/ http://127.0.0.1:1234/
ProxyPassReverse /app1/ http://127.0.0.1:1234/
</Directory>
<Directory /app2/>
SetEnv app2
ProxyPass /app2/ http://127.0.0.1:2234/
ProxyPassReverse /app2/ http://127.0.0.1:2234/
</Directory>
ErrorLog ${APACHE_LOG_DIR}/app1_error.log env=app1
CustomLog ${APACHE_LOG_DIR}/app1_access.log combined env=app1
ErrorLog ${APACHE_LOG_DIR}/app2_error.log env=app2
CustomLog ${APACHE_LOG_DIR}/app2_access.log combined env=app2
# ssh/https settings here
</VirtualHost>
but running apachectl configtest
gives:
[...] Syntax error [...]
ProxyPass cannot occur within section
[...]
This fail is kinda understandable, but what can I do instead to separate logs?
(Or may be the whole VirtualHost approach is not suitable for this and I should do something else?)