apache2 - 如何在 Apache2 中为不同的代理(应用程序)设置不同的日志?
问题描述
我正在使用 Apache2 为“管理”位(例如提供 https、路由等)在服务器上设置多个应用程序,并且当前将它们托管在同一域上的不同路由上,例如
example.com/app1
example.com/app2
对于一个应用程序,我使用过
<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>
然后,我了解到每个域只能有一个虚拟主机,所以我添加了另一个代理来设置正确的路由:
<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>
现在我想知道如何为不同的应用程序设置不同的日志。我可以使用Directory
代理并做这样的事情吗?我试过了
<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>
但运行apachectl configtest
给出:
[...] 语法错误 [...]
ProxyPass 不能在
[...]部分中发生
这种失败是可以理解的,但我能做些什么来分隔日志呢?
(或者可能整个 VirtualHost 方法不适合这个,我应该做点别的?)
解决方案
我只是在头脑风暴。如果这是胡说八道,请随意投反对票:)
<VirtualHost *:443>
ServerName example.com
ProxyPass /app1/ http://127.0.0.1:4431/
ProxyPassReverse /app1/ http://127.0.0.1:4431/
ProxyPass /app2/ http://127.0.0.1:4432/
ProxyPassReverse /app2/ http://127.0.0.1:4432/
</VirtualHost>
<VirtualHost *:4431>
ServerName example.com
ProxyPass /app1/ http://127.0.0.1:1234/
ProxyPassReverse /app1/ http://127.0.0.1:1234/
# Or
# ProxyPass / http://127.0.0.1:1234/
# ProxyPassReverse / http://127.0.0.1:1234/
ErrorLog ${APACHE_LOG_DIR}/app1_error.log
CustomLog ${APACHE_LOG_DIR}/app1_access.log combined
# ssh/https settings here
</VirtualHost>
<VirtualHost *:4432>
ServerName example.com
ProxyPass /app2/ http://127.0.0.1:2234/
ProxyPassReverse /app2/ http://127.0.0.1:2234/
# Or
# ProxyPass / http://127.0.0.1:2234/
# ProxyPassReverse / http://127.0.0.1:2234/
ErrorLog ${APACHE_LOG_DIR}/app2_error.log
CustomLog ${APACHE_LOG_DIR}/app2_access.log combined
# ssh/https settings here
</VirtualHost>
推荐阅读
- r - 计算不同数据帧中出现的次数,并将行号作为字符串获取
- split - 在 PDI 中加载数据时基于列 (DATE) 拆分行
- javascript - 系统自时间较长的 Chrome 性能分析
- sql - 向上取整或向下取整此查询中的 SpecialOfferPrice 列?
- android - 启用暗模式时如何将图像保持为原始形式
- javascript - 位置的阈值比例
- javascript - Jquery 到 javascript 或 Jquery 到伪代码
- mockito - 未调用方法调用时的 Mockito,验证返回消息“想要但未调用,实际上,与此模拟的交互为零”
- typescript - 生成一个类型,其中每个可为空的值都变为可选
- amazon-cloudformation - 如何使用 cloudformation 从 aws 动态读取 ami id