Getting 404 for S3 static website JS behind Apache

2019-08-21 08:53发布

问题:

I have an Apache HTTP Server acting as a proxy in front an AWS S3 static website. So http://example.com/testsite goes to the S3 site, but should keep being seen as being accessed from http://example.com/testsite.

The initial index.html access results in a 200 response, however, all the JavaScript files that get run, return 404. They are located in the S3 root, same as index.html, but they end up being accessed as http://example.com/ instead of http://example.com/testsite, hence why I am getting 404.

I am hoping someone can help me with my Apache config snippet (see below, please), so that I can get the correct configuration.

RedirectMatch permanent ^/$ /doorman/
Redirect /js/ /frontman/js/
...
...
<Location /testsite >
  ProxyPreserveHost On
  AuthType openid-connect
  Require valid-user
  ProxyPass <%= @s3_website %>/
  ProxyPassReverse <%= @s3_website %>/
</Location>

回答1:

I resolved this by using the configuration below:

``` ProxyPreserveHost Off AuthType openid-connect Require valid-user ProxyPass <%= @s3_website %> ProxyPassReverse <%= @s3_website %>

ProxyPreserveHost Off AuthType openid-connect Require valid-user ProxyPass <%= @s3_website %>/assets/$1 ProxyPassReverse <%= @s3_website %>/assets/$1

ProxyPreserveHost Off AuthType openid-connect Require valid-user ProxyPass <%= @s3_website %> ProxyPassReverse <%= @s3_website %> ```

Key pieces are:

"ProxyPreserveHost Off" - My S3 bucket name is different from the proxy so this needs to be "Off".

"LocationMatch " - Required so the proxy can match, and map the URL requests and to the S3 bucket location/object.