apache - 在 Apache 代理后面为 S3 静态网站 JS 获取 404
问题描述
我有一个 Apache HTTP 服务器作为 AWS S3 静态网站前面的代理。所以http://example.com/testsite转到 S3 站点,但应该继续被视为从http://example.com/testsite访问。
初始index.html
访问导致 200 响应,但是,所有运行的 JavaScript 文件都返回 404。它们位于 S3 根目录中,与 相同index.html
,但最终以http://example.com/而不是http://example.com/testsite,因此我得到 404。
我希望有人可以帮助我处理我的 Apache 配置片段(请参见下文),以便我能够获得正确的配置。
RedirectMatch permanent ^/$ /doorman/
Redirect /js/ /frontman/js/
...
...
<Location /testsite >
ProxyPreserveHost On
AuthType openid-connect
Require valid-user
ProxyPass <%= @s3_website %>/
ProxyPassReverse <%= @s3_website %>/
</Location>
解决方案
我通过使用以下配置解决了这个问题:
``` ProxyPreserveHost Off AuthType openid-connect 需要有效用户 ProxyPass <%= @s3_website %> ProxyPassReverse <%= @s3_website %>
ProxyPreserveHost Off AuthType openid-connect 需要有效用户 ProxyPass <%= @s3_website %>/assets/$1 ProxyPassReverse <%= @s3_website %>/assets/$1
ProxyPreserveHost Off AuthType openid-connect 需要有效用户 ProxyPass <%= @s3_website %> ProxyPassReverse <%= @s3_website %> ```
关键部分是:
“ProxyPreserveHost Off” - 我的 S3 存储桶名称与代理不同,因此需要设置为“Off”。
“LocationMatch” - 需要这样代理才能匹配,并将 URL 请求映射到 S3 存储桶位置/对象。
推荐阅读
- javascript - 如何在 jQuery 中将元素存储为对象而不是 HTML 元素?
- angular - 用主数据值替换 id,建议一个适用于所有主数据的通用解决方案?
- node.js - 使用 jest 模拟具有不同实现的泵 node_module - Typescript
- java - 使用 Spring Boot 将 QR 码创建为 Base64 字符串
- python - 现代gl.error.Error:GLSL编译器失败
- prolog - Prolog数独错误,无论如何都返回false
- python - Python Dataframe 日期列 - 将格式更改为 yyyy-mm-dd
- sql - 如何查找两个日期之间的连续天数
- angular - 从 .obj 文件加载的可交互 3D 模型?
- javascript - Ionic:有什么方法可以实现非垂直拖放组件重新排序?