Skip to content

Commit 965ff55

Browse files
Document why FallbackResource should not be used with mod_wsgi.
Add a configuration-issues section explaining that FallbackResource routes via a mod_dir subrequest plus ap_internal_fast_redirect, which makes the main request adopt the subrequest's output filter chain. When the response length becomes unknown (for example under mod_deflate) the response goes chunked but is not chunk framed, hanging clients. This is outside mod_wsgi's control; point users at the Alias and RewriteCond recipes instead, and add a cross-reference label to the Alias section.
1 parent 29ead51 commit 965ff55

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

docs/user-guides/configuration-guidelines.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ configuration, redirect / ``Location``-header rewriting issues,
549549
and the equivalent ``mod_wsgi-express`` options, see
550550
:doc:`running-behind-a-reverse-proxy`.
551551

552+
.. _the-apache-alias-directive:
553+
552554
The Apache Alias Directive
553555
--------------------------
554556

docs/user-guides/configuration-issues.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,53 @@ neither a graceful reload, restart, nor full Apache stop/start is
444444
required. ``touch``-ing the WSGI script file causes the daemon
445445
process group to recycle on the next request, picking up the new
446446
code.
447+
448+
Avoid FallbackResource
449+
----------------------
450+
451+
Do not use the ``FallbackResource`` directive to route requests to a
452+
WSGI application. A configuration of the form::
453+
454+
<Directory /var/www/files/>
455+
FallbackResource /python/
456+
</Directory>
457+
458+
WSGIScriptAlias /python /var/www/wsgi_test.py
459+
460+
is intended to serve static files where they exist and fall back to
461+
the WSGI application for everything else. It does not work reliably and
462+
can produce a corrupted response that causes browsers to hang.
463+
464+
``FallbackResource`` is implemented in ``mod_dir`` by performing a
465+
subrequest for the fallback URL and, when that subrequest resolves to a
466+
regular file, splicing it into the main request with
467+
``ap_internal_fast_redirect()``. Because a WSGI script is a regular
468+
file on disk, that path is taken and the main request adopts the output
469+
filter chain that was built for the subrequest. The WSGI application
470+
then runs against that borrowed filter chain rather than the one the
471+
main request would normally use.
472+
473+
The practical consequence shows up when the response length is not
474+
known up front. If ``mod_deflate`` is compressing the response, for
475+
example, it removes the ``Content-Length`` the application supplied and
476+
Apache switches to ``Transfer-Encoding: chunked``. With the spliced
477+
filter chain the chunk-framing filter is not applied to the body, so
478+
the response is sent without the chunk size markers or the terminating
479+
chunk. Clients wait indefinitely for data that never arrives.
480+
481+
This is a limitation in the way ``FallbackResource`` interacts with
482+
Apache's filter chain and is not something mod_wsgi can detect or
483+
correct, as the affected filters run outside of mod_wsgi's control. To
484+
mix static content with a WSGI application, use the ``Alias`` based
485+
recipe described in
486+
:ref:`the-apache-alias-directive`, or a
487+
``mod_rewrite`` rule that only rewrites to the WSGI application when the
488+
requested file does not exist::
489+
490+
RewriteEngine On
491+
RewriteCond %{REQUEST_FILENAME} !-f
492+
RewriteCond %{REQUEST_FILENAME} !-d
493+
RewriteRule ^ /python/ [PT,L]
494+
495+
Both of these go through normal request processing with a correctly
496+
constructed filter chain and do not exhibit the problem.

0 commit comments

Comments
 (0)