1
votes

I know there are a few threads on this issue out there but all of them have answers from 2019 where other behaviours and features were available, for example, at the time you couldn't even add a bucket as a backend service on a load balancer.

I'm trying to serve files from bucket A from mydomain.com/storage/public and bucket B from mydomain.com/storage/private which isn't an issue.

What I haven't successfully done is to rewrite the path so that I don't have to add all my files in bucket A nested in the folder /storage/public and for bucket B in /storage/private -- but rather just serve them from the root of the bucket.

I have added the following path & host rewrite rule that doesn't work:

host:
path: /*

I'm assuming this tells it to rewrite mydomain.com/storage/public/myfile.png to mydomain.com/myfile.png, but again this doesn't seem to work.

1
Is there any specific reason why you would not want to have the objects stored with their correct path?Jofre
none other than the fact that I don't want to nest my files into folders depending on what's configured on the load balancer -- I'd like to keep the two decoupled. Nonetheless, I have since found the proper syntax for achieving this and it's been working flawlessly in production for several weeks now. Will post the solution later on.SebastianG

1 Answers

0
votes

As I understand that you might have one file eg xyz, .png in public folder so your URL looks like mydomain.com/storage/public/xyz.png

And would like to serve the file(s) from the root folder ie., mydomain.com/storage/xyz.png. You have also attempted to rewrite the paths and were not able to do so. Let me know if I captured your information correctly.

I would recommend you to modify your configuration with below steps: Click edit on your Load balancer Change the host and path rules :

  1. In the left column of the screen, click Host and path rules.
  2. Select Advanced host and path rule (URL redirect, URL rewrite).
  3. Click the row that contains the non-default path rule,
  4. Click the pencil icon edit for the /storage/* Route traffic to a single backend:backend name
  5. Under Paths, delete /storage/* and add /*.
  6. Under Action, select Route traffic to a single backend.
  7. Click Add-on action (URL rewrite).
  8. Leave Host rewrite blank.
  9. Under Path prefix rewrite, enter /storage/.
  10. Under Backend, select backend name and Click Save and Click Done.
  11. If everything looks correct, click Update to update your HTTP load balancer.

Refer the documentation for more information.