Bug 59618 - SCRIPT_FILENAME is prefixed with bogus "proxy:fcgi"
Summary: SCRIPT_FILENAME is prefixed with bogus "proxy:fcgi"
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_proxy_fcgi (show other bugs)
Version: 2.4.20
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Reported: 2016-05-23 16:21 UTC by Jacob Champion
Modified: 2017-04-20 13:20 UTC (History)
1 user (show)

Strip proxy:fcgi as well as proxy:balancer (1.05 KB, patch)
2016-05-23 16:40 UTC, Jacob Champion
Details | Diff
An Apache::Test case (2.35 KB, patch)
2016-05-23 23:10 UTC, Jacob Champion
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jacob Champion 2016-05-23 16:21:29 UTC
Partial duplicate of 50851, but that bug is an omnibus with quite a bit of history behind it and this issue is more easily patched.

When using mod_proxy_fcgi with the recommended SetHandler/Proxy architecture:

  Alias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
  <Location /cgi-bin/>
    SetHandler "proxy:fcgi://localhost:4000"

  <Proxy "fcgi://localhost:4000">

...the SCRIPT_FILENAME passed to the backend is prefixed with proxy:fcgi:

  [Fri May 20 12:08:40.299263 2016] [proxy_fcgi:trace8] [pid 21189:tid 139785465222912] mod_proxy_fcgi.c(294): [client] AH01062: sending env var 'SCRIPT_FILENAME' value 'proxy:fcgi://localhost:4000/usr/local/apache2/cgi-bin/test-cgi'

This makes it difficult to use with general-purpose FCGI backends, since they cannot understand the file path. PHP-FPM appears to have been hard-coded to ignore the prefix as a workaround; see https://bugs.php.net/bug.php?id=54152 .

mod_proxy_fcgi already strips the proxy:balancer prefix; I propose that we add the proxy:fcgi prefix to that logic as well (or refactor the logic so that the internal prefixes aren't considered by the environment variable generation, but that would be significantly more work).
Comment 1 Jacob Champion 2016-05-23 16:40:03 UTC
Created attachment 33865 [details]
Strip proxy:fcgi as well as proxy:balancer

One possible approach. Patch was made against 2.4.20.
Comment 2 Jacob Champion 2016-05-23 23:10:58 UTC
Created attachment 33867 [details]
An Apache::Test case

Here's a test case for the SCRIPT_FILENAME variable.

Regarding the XXX marker in the patch: I couldn't find a way to get the value of a @NextAvailablePort@ from inside the test client. Maybe a new Apache::Test feature is needed? Or we could just hardcode the port number.
Comment 3 Eric Covener 2016-06-10 22:55:21 UTC
Thanks Jacob, fixed in http://svn.apache.org/r1747810 and proposed for 2.4.x.
Comment 4 Graham Leggett 2016-06-13 22:54:28 UTC
Backported to v2.4.21.
Comment 5 Eric Covener 2017-01-08 02:40:53 UTC
Need go to back to the drawing board on this one, php-fpm was using this prefix as a hint that this was a non mod_fastcgi / non Action kind of invocation. When its gone, they're using PATH_TRANSLATED instead of SCRIPT_FILENAME because I guess that's how some Action-based mod_fastcgi configs worked.

I am tempted to flip the default and just guard it under a directive.
Comment 6 Jim Jagielski 2017-04-20 13:20:44 UTC
Modifications in 2.4.26 and later provide workarounds for this.