Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: X-Sendfile/X-Accel-Redirect #896

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

docs: X-Sendfile/X-Accel-Redirect #896

wants to merge 2 commits into from

Conversation

dunglas
Copy link
Owner

@dunglas dunglas commented Jul 2, 2024

Closes #884.
Needs caddyserver/caddy#6429.

@Koc
Copy link

Koc commented Jul 27, 2024

how to deal with that if we're storing files in AWS S3-like storages?

@nicolas-grekas
Copy link

nicolas-grekas commented Sep 5, 2024

It looks like this is missing sending the X-Accel-Mapping header that Symfony needs to generate the correct redirect.
See https://mattbrictson.com/blog/accelerated-rails-downloads for how this works on RoR (Symfony behaves the same).

@withinboredom
Copy link
Collaborator

@nicolas-grekas If I am understanding correctly, this is a header sent from the webserver to PHP?

@nicolas-grekas
Copy link

@withinboredom correct, to advertise the mapping between URL prefix and internal path.

@withinboredom
Copy link
Collaborator

I think this is doable, just needs to be documented. I'll take a look later today.

@dunglas
Copy link
Owner Author

dunglas commented Jan 8, 2025

@nicolas-grekas it's not necessary because we change the root directory (see also dunglas/frankenphp-demo#28)

Copy link
Contributor

@aleho aleho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me with the latest Docker container.

I just noticed a few "problems" when using Symfony.

# ...

+ # Needed for Symfony, Laravel and other projects using the Symfony HttpFoundation component
+ request_header X-Sendfile-Type x-accel-redirect
Copy link
Contributor

@aleho aleho Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without setting X-Accel-Mapping using BinaryFileResponse Symfony would throw an Exception.

The header is not required when setting the X-Accel-Redirect header on a response manually.

Maybe this should be documented too, like, e.g.:

Suggested change
+ request_header X-Sendfile-Type x-accel-redirect
+ request_header X-Sendfile-Type x-accel-redirect
+ # Set the following header if you're using BinaryFileResponse (see below for an example)
+ #request_header X-Accel-Mapping /actual/path/to/private-files=/private-files

+
+ # Remove the X-Accel-Redirect header set by PHP for increased security
+ header -X-Accel-Redirect
+
Copy link
Contributor

@aleho aleho Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be more headers documented in the example?

There are the headers BinaryFileResponse will set.

Suggested change
+
+ copy_response_headers
+

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, never mind. I was thinking of handle_response in Caddy when using fastcgi, where copy_response_headers is needed to get all headers from upstream. In intercept apparently all headers are present anyway (as there's no upstream).

@dunglas
Copy link
Owner Author

dunglas commented Jan 10, 2025

What problems did you have?

@aleho
Copy link
Contributor

aleho commented Jan 10, 2025

What problems did you have?

Only my comments on the review. Any one of them turned out to be wrong assumptions on my end anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"no such file or directory" with handle_response
6 participants