如何解决当 Apache 中的 ProxyPreserveHost 设置为 ON 时,AWS API 网关给出禁止 Apache 反向代理配置API 网关的资源策略
我在单个 apache 服务器上托管多个网站。该服务器实际上位于反向代理之后。此反向代理位于负载平衡器之后。
当我将 ProxyPreserveHost 设置为 On 时,这会保留主机标头。这个指令对我来说是必要的,因为我在同一个 apache 服务器上托管多个站点(UI 文件)。 但是当这个指令设置为 On 时。任何代理到 AWS API 网关的请求都会得到响应
{"message":"Forbidden"}
此 API 网关是私有的。它不能在 AWS VPC 之外直接访问。 当我将 ProxyPreserveHost 设置为关闭时。多个站点无法运行,但所有代理到 AWS API 网关的请求都正常工作。
Apache 反向代理配置
Listen 443
<VirtualHost *:443>
ServerName www.example.com
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
ProxyPreserveHost on
# Rule for API
ProxyPass /custompath/ https://api_id.execute-api.region.amazonaws.com/dev/
ProxyPassReverse /customsample/ https://api_id.execute-api.region.amazonaws.com/dev/
# Rule for Front end application
ProxyPass / https://front-end-loadbalancer/
ProxyPassReverse / https://front-end-loadbalancer/
LogLevel warn
ErrorLog /var/log/httpd/rproxy_error_log
CustomLog /var/log/httpd/rproxy_access_log combined
</VirtualHost>
API 网关的资源策略
{
"Version": "2012-10-17","Statement": [
{
"Effect": "Allow","Principal": "*","Action": "execute-api:Invoke","Resource": [
"execute-api:/*"
]
},{
"Effect": "Deny","Resource": [
"execute-api:/*"
],"Condition" : {
"StringNotEquals": {
"aws:SourceVpc": "vpc-id"
}
}
}
]
}
Apache 版本:2.4
操作系统:CentOS 7.8
我在谷歌上搜索了很多并尝试了 If
和 Location
块也为特定条件打开 proypreservehost,但这些块中不允许使用 ProxyPassReverse 和 ProxyPass。
指令“ProxyPreserveHost On”除了保留主机头之外还有什么作用?
任何正确方向的指导都会非常有帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。