【发布时间】:2017-06-29 11:29:03
【问题描述】:
我在 fasthost DNS 提供商上有一个名为 mywebsite.com 的托管网站。对 mywebsite.com 的任何请求都会转发到运行我的 Web 应用程序的 aws EC2 实例。在 EC2 实例中,我设置了 Apache http 服务器,它接收所有请求并借助 apache httpd.conf 文件中的以下虚拟主机设置转发到我的 Web 应用程序
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mywebsite.com
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
到目前为止,这一切正常。现在我有了在 aws S3 存储桶上托管的静态图像。可公开访问的网址是https://s3.eu-west-2.amazonaws.com/static/images/some-img.png
我不希望出现 S3 域名,并且想屏蔽 s3.eu-west-2.amazonaws.com 服务器名称,所以我有类似的东西而不是 https://s3.eu-west-2.amazonaws.com/static/images/some-img.png
https://mywebsite.com/static/images/some-img.png
我尝试在 httpd.conf 中添加虚拟主机条目,以便将任何带有上下文 /static 的请求转发到 S3 实例。但它似乎不起作用:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mywebsite.com
ProxyPass /static https://s3.eu-west-2.amazonaws.com/
ProxyPassReverse /static https://s3.eu-west-2.amazonaws.com/
</VirtualHost>
知道这是否可能吗?
更新 我将 VirtualHost 修改为
<VirtualHost *:80>
ErrorLog logs/mywebsite.com-error_log
ProxyPreserveHost Off
ProxyRequests Off
ServerName mywebsite.com
ProxyPass /static https://s3.eu-west-2.amazonaws.com/mywebsite-static-repo
ProxyPassReverse /static https://s3.eu-west-2.amazonaws.com/mywebsite-static-repo
</VirtualHost>
其中mywebsite-static-repo 是存储桶的名称。 mywebsite.com-error_log 给出以下错误:
File does not exist: /var/www/html/mywebsite-static-repo
[warn] proxy: No protocol handler was valid for the URL /static/mywebsite-static-repo/images/some-img.png. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
【问题讨论】:
-
我看错了你的问题,所以我删除了我的答案。您应该考虑使用您的自定义域设置 Cloudfront 并将其连接到您的 S3 服务器,以避免 EC2 上传入连接等的重定向开销,从长远来看,CF 还为您提供大量其他好处。
-
这绝对是可能的,但您希望将
ProxyPreserveHost设置为off并在ProxyPass指令中包含存储桶名称,例如...aws.com/bucket/或https://bucket.s3....。请不要说“它似乎不起作用”。描述行为。 -
@Michael-sqlbot 我已根据您的建议更新了问题。
-
@tintin 可能是你没有启用 mod_proxy_http 或 mod_ssl 吗?
标签: apache amazon-s3 amazon-ec2